1/* Copyright (C) 1992-2019 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 <http://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'. */
35enum
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'. */
65enum
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. */
86enum
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'. */
105struct FTW
106 {
107 int base;
108 int level;
109 };
110#endif /* extended X/Open */
111
112
113/* Convenient types for callback functions. */
114typedef int (*__ftw_func_t) (const char *__filename,
115 const struct stat *__status, int __flag);
116#ifdef __USE_LARGEFILE64
117typedef int (*__ftw64_func_t) (const char *__filename,
118 const struct stat64 *__status, int __flag);
119#endif
120#ifdef __USE_XOPEN_EXTENDED
121typedef int (*__nftw_func_t) (const char *__filename,
122 const struct stat *__status, int __flag,
123 struct FTW *__info);
124# ifdef __USE_LARGEFILE64
125typedef 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
136extern int ftw (const char *__dir, __ftw_func_t __func, int __descriptors)
137 __nonnull ((1, 2));
138#else
139# ifdef __REDIRECT
140extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func,
141 int __descriptors), ftw64) __nonnull ((1, 2));
142# else
143# define ftw ftw64
144# endif
145#endif
146#ifdef __USE_LARGEFILE64
147extern int ftw64 (const char *__dir, __ftw64_func_t __func,
148 int __descriptors) __nonnull ((1, 2));
149#endif
150
151#ifdef __USE_XOPEN_EXTENDED
152/* Call a function on every element in a directory tree. FLAG allows
153 to specify the behaviour more detailed.
154
155 This function is a possible cancellation point and therefore not
156 marked with __THROW. */
157# ifndef __USE_FILE_OFFSET64
158extern int nftw (const char *__dir, __nftw_func_t __func, int __descriptors,
159 int __flag) __nonnull ((1, 2));
160# else
161# ifdef __REDIRECT
162extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func,
163 int __descriptors, int __flag), nftw64)
164 __nonnull ((1, 2));
165# else
166# define nftw nftw64
167# endif
168# endif
169# ifdef __USE_LARGEFILE64
170extern int nftw64 (const char *__dir, __nftw64_func_t __func,
171 int __descriptors, int __flag) __nonnull ((1, 2));
172# endif
173#endif
174
175__END_DECLS
176
177#endif /* ftw.h */
178