Back to index

glibc  2.9
ftw.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992,1996-1999,2003,2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  *     X/Open Portability Guide 4.2: ftw.h
00021  */
00022 
00023 #ifndef _FTW_H
00024 #define       _FTW_H 1
00025 
00026 #include <features.h>
00027 
00028 #include <sys/types.h>
00029 #include <sys/stat.h>
00030 
00031 
00032 __BEGIN_DECLS
00033 
00034 /* Values for the FLAG argument to the user function passed to `ftw'
00035    and 'nftw'.  */
00036 enum
00037 {
00038   FTW_F,             /* Regular file.  */
00039 #define FTW_F  FTW_F
00040   FTW_D,             /* Directory.  */
00041 #define FTW_D  FTW_D
00042   FTW_DNR,           /* Unreadable directory.  */
00043 #define FTW_DNR       FTW_DNR
00044   FTW_NS,            /* Unstatable file.  */
00045 #define FTW_NS        FTW_NS
00046 
00047 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00048 
00049   FTW_SL,            /* Symbolic link.  */
00050 # define FTW_SL       FTW_SL
00051 #endif
00052 
00053 #ifdef __USE_XOPEN_EXTENDED
00054 /* These flags are only passed from the `nftw' function.  */
00055   FTW_DP,            /* Directory, all subdirs have been visited. */
00056 # define FTW_DP       FTW_DP
00057   FTW_SLN            /* Symbolic link naming non-existing file.  */
00058 # define FTW_SLN FTW_SLN
00059 
00060 #endif /* extended X/Open */
00061 };
00062 
00063 
00064 #ifdef __USE_XOPEN_EXTENDED
00065 /* Flags for fourth argument of `nftw'.  */
00066 enum
00067 {
00068   FTW_PHYS = 1,             /* Perform physical walk, ignore symlinks.  */
00069 # define FTW_PHYS    FTW_PHYS
00070   FTW_MOUNT = 2,     /* Report only files on same file system as the
00071                         argument.  */
00072 # define FTW_MOUNT   FTW_MOUNT
00073   FTW_CHDIR = 4,     /* Change to current directory while processing it.  */
00074 # define FTW_CHDIR   FTW_CHDIR
00075   FTW_DEPTH = 8             /* Report files in directory before directory itself.*/
00076 # define FTW_DEPTH   FTW_DEPTH
00077 # ifdef __USE_GNU
00078   ,
00079   FTW_ACTIONRETVAL = 16     /* Assume callback to return FTW_* values instead of
00080                         zero to continue and non-zero to terminate.  */
00081 #  define FTW_ACTIONRETVAL FTW_ACTIONRETVAL
00082 # endif
00083 };
00084 
00085 #ifdef __USE_GNU
00086 /* Return values from callback functions.  */
00087 enum
00088 {
00089   FTW_CONTINUE = 0,  /* Continue with next sibling or for FTW_D with the
00090                         first child.  */
00091 # define FTW_CONTINUE       FTW_CONTINUE
00092   FTW_STOP = 1,             /* Return from `ftw' or `nftw' with FTW_STOP as return
00093                         value.  */
00094 # define FTW_STOP    FTW_STOP
00095   FTW_SKIP_SUBTREE = 2,     /* Only meaningful for FTW_D: Don't walk through the
00096                         subtree, instead just continue with its next
00097                         sibling. */
00098 # define FTW_SKIP_SUBTREE FTW_SKIP_SUBTREE
00099   FTW_SKIP_SIBLINGS = 3,/* Continue with FTW_DP callback for current directory
00100                          (if FTW_DEPTH) and then its siblings.  */
00101 # define FTW_SKIP_SIBLINGS FTW_SKIP_SIBLINGS
00102 };
00103 #endif
00104 
00105 /* Structure used for fourth argument to callback function for `nftw'.  */
00106 struct FTW
00107   {
00108     int base;
00109     int level;
00110   };
00111 #endif /* extended X/Open */
00112 
00113 
00114 /* Convenient types for callback functions.  */
00115 typedef int (*__ftw_func_t) (__const char *__filename,
00116                           __const struct stat *__status, int __flag);
00117 #ifdef __USE_LARGEFILE64
00118 typedef int (*__ftw64_func_t) (__const char *__filename,
00119                             __const struct stat64 *__status, int __flag);
00120 #endif
00121 #ifdef __USE_XOPEN_EXTENDED
00122 typedef int (*__nftw_func_t) (__const char *__filename,
00123                            __const struct stat *__status, int __flag,
00124                            struct FTW *__info);
00125 # ifdef __USE_LARGEFILE64
00126 typedef int (*__nftw64_func_t) (__const char *__filename,
00127                             __const struct stat64 *__status,
00128                             int __flag, struct FTW *__info);
00129 # endif
00130 #endif
00131 
00132 /* Call a function on every element in a directory tree.
00133 
00134    This function is a possible cancellation point and therefore not
00135    marked with __THROW.  */
00136 #ifndef __USE_FILE_OFFSET64
00137 extern int ftw (__const char *__dir, __ftw_func_t __func, int __descriptors)
00138      __nonnull ((1, 2));
00139 #else
00140 # ifdef __REDIRECT
00141 extern int __REDIRECT (ftw, (__const char *__dir, __ftw_func_t __func,
00142                           int __descriptors), ftw64) __nonnull ((1, 2));
00143 # else
00144 #  define ftw ftw64
00145 # endif
00146 #endif
00147 #ifdef __USE_LARGEFILE64
00148 extern int ftw64 (__const char *__dir, __ftw64_func_t __func,
00149                 int __descriptors) __nonnull ((1, 2));
00150 #endif
00151 
00152 #ifdef __USE_XOPEN_EXTENDED
00153 /* Call a function on every element in a directory tree.  FLAG allows
00154    to specify the behaviour more detailed.
00155 
00156    This function is a possible cancellation point and therefore not
00157    marked with __THROW.  */
00158 # ifndef __USE_FILE_OFFSET64
00159 extern int nftw (__const char *__dir, __nftw_func_t __func, int __descriptors,
00160                int __flag) __nonnull ((1, 2));
00161 # else
00162 #  ifdef __REDIRECT
00163 extern int __REDIRECT (nftw, (__const char *__dir, __nftw_func_t __func,
00164                            int __descriptors, int __flag), nftw64)
00165      __nonnull ((1, 2));
00166 #  else
00167 #   define nftw nftw64
00168 #  endif
00169 # endif
00170 # ifdef __USE_LARGEFILE64
00171 extern int nftw64 (__const char *__dir, __nftw64_func_t __func,
00172                  int __descriptors, int __flag) __nonnull ((1, 2));
00173 # endif
00174 #endif
00175 
00176 __END_DECLS
00177 
00178 #endif /* ftw.h */