1 | /* Copyright (C) 1992-2022 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
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. |
8 | |
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. |
13 | |
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/>. */ |
17 | |
18 | /* |
19 | * X/Open Portability Guide 4.2: ftw.h |
20 | */ |
21 | |
22 | #ifndef _FTW_H |
23 | #define _FTW_H 1 |
24 | |
25 | #include <features.h> |
26 | |
27 | #include <sys/types.h> |
28 | #include <sys/stat.h> |
29 | |
30 | |
31 | __BEGIN_DECLS |
32 | |
33 | /* Values for the FLAG argument to the user function passed to `ftw' |
34 | and 'nftw'. */ |
35 | enum |
36 | { |
37 | FTW_F, /* Regular file. */ |
38 | #define FTW_F FTW_F |
39 | FTW_D, /* Directory. */ |
40 | #define FTW_D FTW_D |
41 | FTW_DNR, /* Unreadable directory. */ |
42 | #define FTW_DNR FTW_DNR |
43 | FTW_NS, /* Unstatable file. */ |
44 | #define FTW_NS FTW_NS |
45 | |
46 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
47 | |
48 | FTW_SL, /* Symbolic link. */ |
49 | # define FTW_SL FTW_SL |
50 | #endif |
51 | |
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 |
58 | |
59 | #endif /* extended X/Open */ |
60 | }; |
61 | |
62 | |
63 | #ifdef __USE_XOPEN_EXTENDED |
64 | /* Flags for fourth argument of `nftw'. */ |
65 | enum |
66 | { |
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 |
70 | argument. */ |
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 |
76 | # ifdef __USE_GNU |
77 | , |
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 |
81 | # endif |
82 | }; |
83 | |
84 | #ifdef __USE_GNU |
85 | /* Return values from callback functions. */ |
86 | enum |
87 | { |
88 | FTW_CONTINUE = 0, /* Continue with next sibling or for FTW_D with the |
89 | first child. */ |
90 | # define FTW_CONTINUE FTW_CONTINUE |
91 | FTW_STOP = 1, /* Return from `ftw' or `nftw' with FTW_STOP as return |
92 | value. */ |
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 |
96 | sibling. */ |
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 |
101 | }; |
102 | #endif |
103 | |
104 | /* Structure used for fourth argument to callback function for `nftw'. */ |
105 | struct FTW |
106 | { |
107 | int base; |
108 | int level; |
109 | }; |
110 | #endif /* extended X/Open */ |
111 | |
112 | |
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); |
119 | #endif |
120 | #ifdef __USE_XOPEN_EXTENDED |
121 | typedef int (*__nftw_func_t) (const char *__filename, |
122 | const struct stat *__status, int __flag, |
123 | struct FTW *__info); |
124 | # ifdef __USE_LARGEFILE64 |
125 | typedef int (*__nftw64_func_t) (const char *__filename, |
126 | const struct stat64 *__status, |
127 | int __flag, struct FTW *__info); |
128 | # endif |
129 | #endif |
130 | |
131 | /* Call a function on every element in a directory tree. |
132 | |
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) |
137 | __nonnull ((1, 2)); |
138 | #else |
139 | # ifdef __REDIRECT |
140 | # ifndef __USE_TIME_BITS64 |
141 | extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func, |
142 | int __descriptors), ftw64) __nonnull ((1, 2)); |
143 | # else |
144 | extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func, |
145 | int __descriptors), __ftw64_time64) |
146 | __nonnull ((1, 2)); |
147 | # endif |
148 | # else |
149 | # ifndef __USE_TIME_BITS64 |
150 | # define ftw ftw64 |
151 | # else |
152 | # define ftw __ftw64_time64 |
153 | # endif |
154 | # endif |
155 | #endif |
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)); |
160 | # else |
161 | # ifdef __REDIRECT |
162 | extern int __REDIRECT (ftw64, (const char *__dir, __ftw64_func_t __func, |
163 | int __descriptors), |
164 | __ftw64_time64) |
165 | __nonnull ((1, 2)); |
166 | # else |
167 | # define nftw64 __nftw64_time64 |
168 | # endif |
169 | # endif |
170 | #endif |
171 | |
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. |
175 | |
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)); |
181 | # else |
182 | # ifdef __REDIRECT |
183 | # ifndef __USE_TIME_BITS64 |
184 | extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func, |
185 | int __descriptors, int __flag), nftw64) |
186 | __nonnull ((1, 2)); |
187 | # else |
188 | extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func, |
189 | int __descriptors, int __flag), __nftw64_time64) |
190 | __nonnull ((1, 2)); |
191 | # endif |
192 | # else |
193 | # ifndef __USE_TIME_BITS64 |
194 | # define nftw nftw64 |
195 | # else |
196 | # define nftw __nftw64_time64 |
197 | # endif |
198 | # endif |
199 | # endif |
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)); |
204 | # else |
205 | # ifdef __REDIRECT |
206 | extern int __REDIRECT (nftw64, (const char *__dir, __nftw64_func_t __func, |
207 | int __descriptors, int __flag), |
208 | __nftw64_time64) |
209 | __nonnull ((1, 2)); |
210 | # else |
211 | # define nftw64 __nftw64_time64 |
212 | # endif |
213 | # endif |
214 | # endif |
215 | #endif |
216 | |
217 | __END_DECLS |
218 | |
219 | #endif /* ftw.h */ |
220 | |