master
  1/* File tree traversal functions declarations.
  2   Copyright (C) 1994-2025 Free Software Foundation, Inc.
  3   This file is part of the GNU C Library.
  4
  5   The GNU C Library is free software; you can redistribute it and/or
  6   modify it under the terms of the GNU Lesser General Public
  7   License as published by the Free Software Foundation; either
  8   version 2.1 of the License, or (at your option) any later version.
  9
 10   The GNU C Library is distributed in the hope that it will be useful,
 11   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13   Lesser General Public License for more details.
 14
 15   You should have received a copy of the GNU Lesser General Public
 16   License along with the GNU C Library; if not, see
 17   <https://www.gnu.org/licenses/>.  */
 18
 19/*
 20 * Copyright (c) 1989, 1993
 21 *	The Regents of the University of California.  All rights reserved.
 22 *
 23 * Redistribution and use in source and binary forms, with or without
 24 * modification, are permitted provided that the following conditions
 25 * are met:
 26 * 1. Redistributions of source code must retain the above copyright
 27 *    notice, this list of conditions and the following disclaimer.
 28 * 2. Redistributions in binary form must reproduce the above copyright
 29 *    notice, this list of conditions and the following disclaimer in the
 30 *    documentation and/or other materials provided with the distribution.
 31 * 4. Neither the name of the University nor the names of its contributors
 32 *    may be used to endorse or promote products derived from this software
 33 *    without specific prior written permission.
 34 *
 35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 45 * SUCH DAMAGE.
 46 *
 47 *	@(#)fts.h	8.3 (Berkeley) 8/14/94
 48 */
 49
 50#ifndef	_FTS_H
 51#define	_FTS_H 1
 52
 53#include <features.h>
 54#include <sys/types.h>
 55
 56
 57typedef struct {
 58	struct _ftsent *fts_cur;	/* current node */
 59	struct _ftsent *fts_child;	/* linked list of children */
 60	struct _ftsent **fts_array;	/* sort array */
 61	dev_t fts_dev;			/* starting device # */
 62	char *fts_path;			/* path for this descent */
 63	int fts_rfd;			/* fd for root */
 64	int fts_pathlen;		/* sizeof(path) */
 65	int fts_nitems;			/* elements in the sort array */
 66	int (*fts_compar) (const void *, const void *); /* compare fn */
 67
 68#define	FTS_COMFOLLOW	0x0001		/* follow command line symlinks */
 69#define	FTS_LOGICAL	0x0002		/* logical walk */
 70#define	FTS_NOCHDIR	0x0004		/* don't change directories */
 71#define	FTS_NOSTAT	0x0008		/* don't get stat info */
 72#define	FTS_PHYSICAL	0x0010		/* physical walk */
 73#define	FTS_SEEDOT	0x0020		/* return dot and dot-dot */
 74#define	FTS_XDEV	0x0040		/* don't cross devices */
 75#define FTS_WHITEOUT	0x0080		/* return whiteout information */
 76#define	FTS_OPTIONMASK	0x00ff		/* valid user option mask */
 77
 78#define	FTS_NAMEONLY	0x0100		/* (private) child names only */
 79#define	FTS_STOP	0x0200		/* (private) unrecoverable error */
 80	int fts_options;		/* fts_open options, global flags */
 81} FTS;
 82
 83#ifdef __USE_LARGEFILE64
 84typedef struct {
 85	struct _ftsent64 *fts_cur;	/* current node */
 86	struct _ftsent64 *fts_child;	/* linked list of children */
 87	struct _ftsent64 **fts_array;	/* sort array */
 88	dev_t fts_dev;			/* starting device # */
 89	char *fts_path;			/* path for this descent */
 90	int fts_rfd;			/* fd for root */
 91	int fts_pathlen;		/* sizeof(path) */
 92	int fts_nitems;			/* elements in the sort array */
 93	int (*fts_compar) (const void *, const void *); /* compare fn */
 94	int fts_options;		/* fts_open options, global flags */
 95} FTS64;
 96#endif
 97
 98typedef struct _ftsent {
 99	struct _ftsent *fts_cycle;	/* cycle node */
100	struct _ftsent *fts_parent;	/* parent directory */
101	struct _ftsent *fts_link;	/* next file in directory */
102	long fts_number;	        /* local numeric value */
103	void *fts_pointer;	        /* local address value */
104	char *fts_accpath;		/* access path */
105	char *fts_path;			/* root path */
106	int fts_errno;			/* errno for this node */
107	int fts_symfd;			/* fd for symlink */
108	unsigned short fts_pathlen;	/* strlen(fts_path) */
109	unsigned short fts_namelen;	/* strlen(fts_name) */
110
111	ino_t fts_ino;			/* inode */
112	dev_t fts_dev;			/* device */
113	nlink_t fts_nlink;		/* link count */
114
115#define	FTS_ROOTPARENTLEVEL	-1
116#define	FTS_ROOTLEVEL		 0
117	short fts_level;		/* depth (-1 to N) */
118
119#define	FTS_D		 1		/* preorder directory */
120#define	FTS_DC		 2		/* directory that causes cycles */
121#define	FTS_DEFAULT	 3		/* none of the above */
122#define	FTS_DNR		 4		/* unreadable directory */
123#define	FTS_DOT		 5		/* dot or dot-dot */
124#define	FTS_DP		 6		/* postorder directory */
125#define	FTS_ERR		 7		/* error; errno is set */
126#define	FTS_F		 8		/* regular file */
127#define	FTS_INIT	 9		/* initialized only */
128#define	FTS_NS		10		/* stat(2) failed */
129#define	FTS_NSOK	11		/* no stat(2) requested */
130#define	FTS_SL		12		/* symbolic link */
131#define	FTS_SLNONE	13		/* symbolic link without target */
132#define FTS_W		14		/* whiteout object */
133	unsigned short fts_info;	/* user flags for FTSENT structure */
134
135#define	FTS_DONTCHDIR	 0x01		/* don't chdir .. to the parent */
136#define	FTS_SYMFOLLOW	 0x02		/* followed a symlink to get here */
137	unsigned short fts_flags;	/* private flags for FTSENT structure */
138
139#define	FTS_AGAIN	 1		/* read node again */
140#define	FTS_FOLLOW	 2		/* follow symbolic link */
141#define	FTS_NOINSTR	 3		/* no instructions */
142#define	FTS_SKIP	 4		/* discard node */
143	unsigned short fts_instr;	/* fts_set() instructions */
144
145	struct stat *fts_statp;		/* stat(2) information */
146	char fts_name[1];		/* file name */
147} FTSENT;
148
149#ifdef __USE_LARGEFILE64
150// zig patch: 64bits variants appeared starting from glibc 2.23
151# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23) || __GLIBC__ > 2
152typedef struct _ftsent64 {
153	struct _ftsent64 *fts_cycle;	/* cycle node */
154	struct _ftsent64 *fts_parent;	/* parent directory */
155	struct _ftsent64 *fts_link;	/* next file in directory */
156	long fts_number;	        /* local numeric value */
157	void *fts_pointer;	        /* local address value */
158	char *fts_accpath;		/* access path */
159	char *fts_path;			/* root path */
160	int fts_errno;			/* errno for this node */
161	int fts_symfd;			/* fd for symlink */
162	unsigned short fts_pathlen;		/* strlen(fts_path) */
163	unsigned short fts_namelen;		/* strlen(fts_name) */
164
165	ino64_t fts_ino;		/* inode */
166	dev_t fts_dev;			/* device */
167	nlink_t fts_nlink;		/* link count */
168
169	short fts_level;		/* depth (-1 to N) */
170
171	unsigned short fts_info;	/* user flags for FTSENT structure */
172
173	unsigned short fts_flags;	/* private flags for FTSENT structure */
174
175	unsigned short fts_instr;	/* fts_set() instructions */
176
177	struct stat64 *fts_statp;	/* stat(2) information */
178	char fts_name[1];		/* file name */
179} FTSENT64;
180# endif
181#endif
182
183__BEGIN_DECLS
184
185// zig patch: 64bits variants appeared starting from glibc 2.23
186// before that version, we can't declare nor redirect to them
187#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23) || __GLIBC__ > 2
188
189#ifndef __USE_FILE_OFFSET64
190FTSENT	*fts_children (FTS *, int);
191int	 fts_close (FTS *);
192FTS	*fts_open (char * const *, int,
193		   int (*)(const FTSENT **, const FTSENT **));
194FTSENT	*fts_read (FTS *);
195int	 fts_set (FTS *, FTSENT *, int) __THROW;
196#else
197# ifdef __REDIRECT
198#  ifndef __USE_TIME64_REDIRECTS
199FTSENT	*__REDIRECT (fts_children, (FTS *, int), fts64_children);
200int	 __REDIRECT (fts_close, (FTS *), fts64_close);
201FTS	*__REDIRECT (fts_open, (char * const *, int,
202				int (*)(const FTSENT **, const FTSENT **)),
203		     fts64_open);
204FTSENT	*__REDIRECT (fts_read, (FTS *), fts64_read);
205int	 __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set);
206#  else
207FTSENT	*__REDIRECT (fts_children, (FTS *, int), __fts64_children_time64);
208int	 __REDIRECT (fts_close, (FTS *), __fts64_close_time64);
209FTS	*__REDIRECT (fts_open, (char * const *, int,
210				int (*)(const FTSENT **, const FTSENT **)),
211		     __fts64_open_time64);
212FTSENT	*__REDIRECT (fts_read, (FTS *), __fts64_read_time64);
213int	 __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int),
214			 __fts64_set_time64);
215#  endif
216# else
217#  ifndef __USE_TIME64_REDIRECTS
218#   define fts_children fts64_children
219#   define fts_close fts64_close
220#   define fts_open fts64_open
221#   define fts_read fts64_read
222#   define fts_set fts64_set
223#  else
224#  endif
225# endif
226#endif
227#else /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23) || __GLIBC__ > 2 */
228FTSENT	*fts_children (FTS *, int);
229int	 fts_close (FTS *);
230FTS	*fts_open (char * const *, int,
231		   int (*)(const FTSENT **, const FTSENT **));
232FTSENT	*fts_read (FTS *);
233int	 fts_set (FTS *, FTSENT *, int) __THROW;
234#endif
235
236// zig patch: 64bits time variants appeared starting from glibc 2.34
237// before that version, there is nothing to declare
238#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34) || __GLIBC__ > 2
239
240#ifdef __USE_LARGEFILE64
241# ifndef __USE_TIME64_REDIRECTS
242FTSENT64 *fts64_children (FTS64 *, int);
243int	  fts64_close (FTS64 *);
244FTS64	 *fts64_open (char * const *, int,
245		      int (*)(const FTSENT64 **, const FTSENT64 **));
246FTSENT64 *fts64_read (FTS64 *);
247int	 fts64_set (FTS64 *, FTSENT64 *, int) __THROW;
248# else
249#  ifdef __REDIRECT
250FTSENT	*__REDIRECT (fts64_children, (FTS64 *, int), __fts64_children_time64);
251int	 __REDIRECT (fts64_close, (FTS64 *), __fts64_close_time64);
252FTS	*__REDIRECT (fts64_open, (char * const *, int,
253				int (*)(const FTSENT64 **, const FTSENT64 **)),
254		     __fts64_open_time64);
255FTSENT	*__REDIRECT (fts64_read, (FTS64 *), __fts64_read_time64);
256int	 __REDIRECT_NTH (fts64_set, (FTS64 *, FTSENT64 *, int),
257			 __fts64_set_time64);
258#  else
259#   define fts_children __fts64_children_time64
260#   define fts_close __fts64_close_time64
261#   define fts_open __fts64_open_time64
262#   define fts_read __fts64_read_time64
263#   define fts_set __fts64_set_time64
264#  endif
265# endif
266#endif
267
268#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34) || __GLIBC__ > 2 */
269__END_DECLS
270
271#endif /* fts.h */