1/* File tree traversal functions declarations.
2 Copyright (C) 1994-2022 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
150typedef struct _ftsent64 {
151 struct _ftsent64 *fts_cycle; /* cycle node */
152 struct _ftsent64 *fts_parent; /* parent directory */
153 struct _ftsent64 *fts_link; /* next file in directory */
154 long fts_number; /* local numeric value */
155 void *fts_pointer; /* local address value */
156 char *fts_accpath; /* access path */
157 char *fts_path; /* root path */
158 int fts_errno; /* errno for this node */
159 int fts_symfd; /* fd for symlink */
160 unsigned short fts_pathlen; /* strlen(fts_path) */
161 unsigned short fts_namelen; /* strlen(fts_name) */
162
163 ino64_t fts_ino; /* inode */
164 dev_t fts_dev; /* device */
165 nlink_t fts_nlink; /* link count */
166
167 short fts_level; /* depth (-1 to N) */
168
169 unsigned short fts_info; /* user flags for FTSENT structure */
170
171 unsigned short fts_flags; /* private flags for FTSENT structure */
172
173 unsigned short fts_instr; /* fts_set() instructions */
174
175 struct stat64 *fts_statp; /* stat(2) information */
176 char fts_name[1]; /* file name */
177} FTSENT64;
178#endif
179
180__BEGIN_DECLS
181#ifndef __USE_FILE_OFFSET64
182FTSENT *fts_children (FTS *, int);
183int fts_close (FTS *);
184FTS *fts_open (char * const *, int,
185 int (*)(const FTSENT **, const FTSENT **));
186FTSENT *fts_read (FTS *);
187int fts_set (FTS *, FTSENT *, int) __THROW;
188#else
189# ifdef __REDIRECT
190# ifndef __USE_TIME_BITS64
191FTSENT *__REDIRECT (fts_children, (FTS *, int), fts64_children);
192int __REDIRECT (fts_close, (FTS *), fts64_close);
193FTS *__REDIRECT (fts_open, (char * const *, int,
194 int (*)(const FTSENT **, const FTSENT **)),
195 fts64_open);
196FTSENT *__REDIRECT (fts_read, (FTS *), fts64_read);
197int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set);
198# else
199FTSENT *__REDIRECT (fts_children, (FTS *, int), __fts64_children_time64);
200int __REDIRECT (fts_close, (FTS *), __fts64_close_time64);
201FTS *__REDIRECT (fts_open, (char * const *, int,
202 int (*)(const FTSENT **, const FTSENT **)),
203 __fts64_open_time64);
204FTSENT *__REDIRECT (fts_read, (FTS *), __fts64_read_time64);
205int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int),
206 __fts64_set_time64);
207# endif
208# else
209# ifndef __USE_TIME_BITS64
210# define fts_children fts64_children
211# define fts_close fts64_close
212# define fts_open fts64_open
213# define fts_read fts64_read
214# define fts_set fts64_set
215# else
216# endif
217# endif
218#endif
219#ifdef __USE_LARGEFILE64
220# ifndef __USE_TIME_BITS64
221FTSENT64 *fts64_children (FTS64 *, int);
222int fts64_close (FTS64 *);
223FTS64 *fts64_open (char * const *, int,
224 int (*)(const FTSENT64 **, const FTSENT64 **));
225FTSENT64 *fts64_read (FTS64 *);
226int fts64_set (FTS64 *, FTSENT64 *, int) __THROW;
227# else
228# ifdef __REDIRECT
229FTSENT *__REDIRECT (fts64_children, (FTS64 *, int), __fts64_children_time64);
230int __REDIRECT (fts64_close, (FTS64 *), __fts64_close_time64);
231FTS *__REDIRECT (fts64_open, (char * const *, int,
232 int (*)(const FTSENT64 **, const FTSENT64 **)),
233 __fts64_open_time64);
234FTSENT *__REDIRECT (fts64_read, (FTS64 *), __fts64_read_time64);
235int __REDIRECT_NTH (fts64_set, (FTS64 *, FTSENT64 *, int),
236 __fts64_set_time64);
237# else
238# define fts_children __fts64_children_time64
239# define fts_close __fts64_close_time64
240# define fts_open __fts64_open_time64
241# define fts_read __fts64_read_time64
242# define fts_set __fts64_set_time64
243# endif
244# endif
245#endif
246__END_DECLS
247
248#endif /* fts.h */
249

source code of include/fts.h