1 /* Copyright (C) 1992-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 * X/Open Portability Guide 4.2: ftw.h
27 #include <sys/types.h>
33 /* Values for the FLAG argument to the user function passed to `ftw'
37 FTW_F
, /* Regular file. */
39 FTW_D
, /* Directory. */
41 FTW_DNR
, /* Unreadable directory. */
42 #define FTW_DNR FTW_DNR
43 FTW_NS
, /* Unstatable file. */
46 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
48 FTW_SL
, /* Symbolic link. */
49 # define FTW_SL FTW_SL
52 #ifdef __USE_XOPEN_EXTENDED
53 /* These flags are only passed from the `nftw' function. */
54 FTW_DP
, /* Directory, all subdirs have been visited. */
55 # define FTW_DP FTW_DP
56 FTW_SLN
/* Symbolic link naming non-existing file. */
57 # define FTW_SLN FTW_SLN
59 #endif /* extended X/Open */
63 #ifdef __USE_XOPEN_EXTENDED
64 /* Flags for fourth argument of `nftw'. */
67 FTW_PHYS
= 1, /* Perform physical walk, ignore symlinks. */
68 # define FTW_PHYS FTW_PHYS
69 FTW_MOUNT
= 2, /* Report only files on same file system as the
71 # define FTW_MOUNT FTW_MOUNT
72 FTW_CHDIR
= 4, /* Change to current directory while processing it. */
73 # define FTW_CHDIR FTW_CHDIR
74 FTW_DEPTH
= 8 /* Report files in directory before directory itself.*/
75 # define FTW_DEPTH FTW_DEPTH
78 FTW_ACTIONRETVAL
= 16 /* Assume callback to return FTW_* values instead of
79 zero to continue and non-zero to terminate. */
80 # define FTW_ACTIONRETVAL FTW_ACTIONRETVAL
85 /* Return values from callback functions. */
88 FTW_CONTINUE
= 0, /* Continue with next sibling or for FTW_D with the
90 # define FTW_CONTINUE FTW_CONTINUE
91 FTW_STOP
= 1, /* Return from `ftw' or `nftw' with FTW_STOP as return
93 # define FTW_STOP FTW_STOP
94 FTW_SKIP_SUBTREE
= 2, /* Only meaningful for FTW_D: Don't walk through the
95 subtree, instead just continue with its next
97 # define FTW_SKIP_SUBTREE FTW_SKIP_SUBTREE
98 FTW_SKIP_SIBLINGS
= 3,/* Continue with FTW_DP callback for current directory
99 (if FTW_DEPTH) and then its siblings. */
100 # define FTW_SKIP_SIBLINGS FTW_SKIP_SIBLINGS
104 /* Structure used for fourth argument to callback function for `nftw'. */
110 #endif /* extended X/Open */
113 /* Convenient types for callback functions. */
114 typedef int (*__ftw_func_t
) (const char *__filename
,
115 const struct stat
*__status
, int __flag
);
116 #ifdef __USE_LARGEFILE64
117 typedef int (*__ftw64_func_t
) (const char *__filename
,
118 const struct stat64
*__status
, int __flag
);
120 #ifdef __USE_XOPEN_EXTENDED
121 typedef int (*__nftw_func_t
) (const char *__filename
,
122 const struct stat
*__status
, int __flag
,
124 # ifdef __USE_LARGEFILE64
125 typedef int (*__nftw64_func_t
) (const char *__filename
,
126 const struct stat64
*__status
,
127 int __flag
, struct FTW
*__info
);
131 /* Call a function on every element in a directory tree.
133 This function is a possible cancellation point and therefore not
134 marked with __THROW. */
135 #ifndef __USE_FILE_OFFSET64
136 extern int ftw (const char *__dir
, __ftw_func_t __func
, int __descriptors
)
140 # ifndef __USE_TIME_BITS64
141 extern int __REDIRECT (ftw
, (const char *__dir
, __ftw_func_t __func
,
142 int __descriptors
), ftw64
) __nonnull ((1, 2));
144 extern int __REDIRECT (ftw
, (const char *__dir
, __ftw_func_t __func
,
145 int __descriptors
), __ftw64_time64
)
149 # ifndef __USE_TIME_BITS64
152 # define ftw __ftw64_time64
156 #ifdef __USE_LARGEFILE64
157 # ifndef __USE_TIME_BITS64
158 extern int ftw64 (const char *__dir
, __ftw64_func_t __func
,
159 int __descriptors
) __nonnull ((1, 2));
162 extern int __REDIRECT (ftw64
, (const char *__dir
, __ftw64_func_t __func
,
167 # define nftw64 __nftw64_time64
172 #ifdef __USE_XOPEN_EXTENDED
173 /* Call a function on every element in a directory tree. FLAG allows
174 to specify the behaviour more detailed.
176 This function is a possible cancellation point and therefore not
177 marked with __THROW. */
178 # ifndef __USE_FILE_OFFSET64
179 extern int nftw (const char *__dir
, __nftw_func_t __func
, int __descriptors
,
180 int __flag
) __nonnull ((1, 2));
183 # ifndef __USE_TIME_BITS64
184 extern int __REDIRECT (nftw
, (const char *__dir
, __nftw_func_t __func
,
185 int __descriptors
, int __flag
), nftw64
)
188 extern int __REDIRECT (nftw
, (const char *__dir
, __nftw_func_t __func
,
189 int __descriptors
, int __flag
), __nftw64_time64
)
193 # ifndef __USE_TIME_BITS64
196 # define nftw __nftw64_time64
200 # ifdef __USE_LARGEFILE64
201 # ifndef __USE_TIME_BITS64
202 extern int nftw64 (const char *__dir
, __nftw64_func_t __func
,
203 int __descriptors
, int __flag
) __nonnull ((1, 2));
206 extern int __REDIRECT (nftw64
, (const char *__dir
, __nftw64_func_t __func
,
207 int __descriptors
, int __flag
),
211 # define nftw64 __nftw64_time64