ftw.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 1992,1996-1999,2003,2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * X/Open Portability Guide 4.2: ftw.h
  17. */
  18. #ifndef _FTW_H
  19. #define _FTW_H 1
  20. #include <features.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. __BEGIN_DECLS
  24. /* Values for the FLAG argument to the user function passed to `ftw'
  25. and 'nftw'. */
  26. enum
  27. {
  28. FTW_F, /* Regular file. */
  29. #define FTW_F FTW_F
  30. FTW_D, /* Directory. */
  31. #define FTW_D FTW_D
  32. FTW_DNR, /* Unreadable directory. */
  33. #define FTW_DNR FTW_DNR
  34. FTW_NS, /* Unstatable file. */
  35. #define FTW_NS FTW_NS
  36. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  37. FTW_SL, /* Symbolic link. */
  38. # define FTW_SL FTW_SL
  39. #endif
  40. #ifdef __USE_XOPEN_EXTENDED
  41. /* These flags are only passed from the `nftw' function. */
  42. FTW_DP, /* Directory, all subdirs have been visited. */
  43. # define FTW_DP FTW_DP
  44. FTW_SLN /* Symbolic link naming non-existing file. */
  45. # define FTW_SLN FTW_SLN
  46. #endif /* extended X/Open */
  47. };
  48. #ifdef __USE_XOPEN_EXTENDED
  49. /* Flags for fourth argument of `nftw'. */
  50. enum
  51. {
  52. FTW_PHYS = 1, /* Perform physical walk, ignore symlinks. */
  53. # define FTW_PHYS FTW_PHYS
  54. FTW_MOUNT = 2, /* Report only files on same file system as the
  55. argument. */
  56. # define FTW_MOUNT FTW_MOUNT
  57. FTW_CHDIR = 4, /* Change to current directory while processing it. */
  58. # define FTW_CHDIR FTW_CHDIR
  59. FTW_DEPTH = 8 /* Report files in directory before directory itself.*/
  60. # define FTW_DEPTH FTW_DEPTH
  61. # ifdef __USE_GNU
  62. ,
  63. FTW_ACTIONRETVAL = 16 /* Assume callback to return FTW_* values instead of
  64. zero to continue and non-zero to terminate. */
  65. # define FTW_ACTIONRETVAL FTW_ACTIONRETVAL
  66. # endif
  67. };
  68. #ifdef __USE_GNU
  69. /* Return values from callback functions. */
  70. enum
  71. {
  72. FTW_CONTINUE = 0, /* Continue with next sibling or for FTW_D with the
  73. first child. */
  74. # define FTW_CONTINUE FTW_CONTINUE
  75. FTW_STOP = 1, /* Return from `ftw' or `nftw' with FTW_STOP as return
  76. value. */
  77. # define FTW_STOP FTW_STOP
  78. FTW_SKIP_SUBTREE = 2, /* Only meaningful for FTW_D: Don't walk through the
  79. subtree, instead just continue with its next
  80. sibling. */
  81. # define FTW_SKIP_SUBTREE FTW_SKIP_SUBTREE
  82. FTW_SKIP_SIBLINGS = 3,/* Continue with FTW_DP callback for current directory
  83. (if FTW_DEPTH) and then its siblings. */
  84. # define FTW_SKIP_SIBLINGS FTW_SKIP_SIBLINGS
  85. };
  86. #endif
  87. /* Structure used for fourth argument to callback function for `nftw'. */
  88. struct FTW
  89. {
  90. int base;
  91. int level;
  92. };
  93. #endif /* extended X/Open */
  94. /* Convenient types for callback functions. */
  95. typedef int (*__ftw_func_t) (__const char *__filename,
  96. __const struct stat *__status, int __flag);
  97. #ifdef __USE_LARGEFILE64
  98. typedef int (*__ftw64_func_t) (__const char *__filename,
  99. __const struct stat64 *__status, int __flag);
  100. #endif
  101. #ifdef __USE_XOPEN_EXTENDED
  102. typedef int (*__nftw_func_t) (__const char *__filename,
  103. __const struct stat *__status, int __flag,
  104. struct FTW *__info);
  105. # ifdef __USE_LARGEFILE64
  106. typedef int (*__nftw64_func_t) (__const char *__filename,
  107. __const struct stat64 *__status,
  108. int __flag, struct FTW *__info);
  109. # endif
  110. #endif
  111. /* Call a function on every element in a directory tree.
  112. This function is a possible cancellation point and therefore not
  113. marked with __THROW. */
  114. #ifndef __USE_FILE_OFFSET64
  115. extern int ftw (__const char *__dir, __ftw_func_t __func, int __descriptors)
  116. __nonnull ((1, 2));
  117. #else
  118. # ifdef __REDIRECT
  119. extern int __REDIRECT (ftw, (__const char *__dir, __ftw_func_t __func,
  120. int __descriptors), ftw64) __nonnull ((1, 2));
  121. # else
  122. # define ftw ftw64
  123. # endif
  124. #endif
  125. #ifdef __USE_LARGEFILE64
  126. extern int ftw64 (__const char *__dir, __ftw64_func_t __func,
  127. int __descriptors) __nonnull ((1, 2));
  128. #endif
  129. #ifdef __USE_XOPEN_EXTENDED
  130. /* Call a function on every element in a directory tree. FLAG allows
  131. to specify the behaviour more detailed.
  132. This function is a possible cancellation point and therefore not
  133. marked with __THROW. */
  134. # ifndef __USE_FILE_OFFSET64
  135. extern int nftw (__const char *__dir, __nftw_func_t __func, int __descriptors,
  136. int __flag) __nonnull ((1, 2));
  137. # else
  138. # ifdef __REDIRECT
  139. extern int __REDIRECT (nftw, (__const char *__dir, __nftw_func_t __func,
  140. int __descriptors, int __flag), nftw64)
  141. __nonnull ((1, 2));
  142. # else
  143. # define nftw nftw64
  144. # endif
  145. # endif
  146. # ifdef __USE_LARGEFILE64
  147. extern int nftw64 (__const char *__dir, __nftw64_func_t __func,
  148. int __descriptors, int __flag) __nonnull ((1, 2));
  149. # endif
  150. #endif
  151. __END_DECLS
  152. #endif /* ftw.h */