ftw.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * X/Open Portability Guide 4.2: ftw.h
  16. */
  17. #ifndef _FTW_H
  18. #define _FTW_H 1
  19. #include <features.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. __BEGIN_DECLS
  23. /* Values for the FLAG argument to the user function passed to `ftw'
  24. and 'nftw'. */
  25. enum
  26. {
  27. FTW_F, /* Regular file. */
  28. #define FTW_F FTW_F
  29. FTW_D, /* Directory. */
  30. #define FTW_D FTW_D
  31. FTW_DNR, /* Unreadable directory. */
  32. #define FTW_DNR FTW_DNR
  33. FTW_NS, /* Unstatable file. */
  34. #define FTW_NS FTW_NS
  35. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  36. FTW_SL, /* Symbolic link. */
  37. # define FTW_SL FTW_SL
  38. #endif
  39. #ifdef __USE_XOPEN_EXTENDED
  40. /* These flags are only passed from the `nftw' function. */
  41. FTW_DP, /* Directory, all subdirs have been visited. */
  42. # define FTW_DP FTW_DP
  43. FTW_SLN /* Symbolic link naming non-existing file. */
  44. # define FTW_SLN FTW_SLN
  45. #endif /* extended X/Open */
  46. };
  47. #ifdef __USE_XOPEN_EXTENDED
  48. /* Flags for fourth argument of `nftw'. */
  49. enum
  50. {
  51. FTW_PHYS = 1, /* Perform physical walk, ignore symlinks. */
  52. # define FTW_PHYS FTW_PHYS
  53. FTW_MOUNT = 2, /* Report only files on same file system as the
  54. argument. */
  55. # define FTW_MOUNT FTW_MOUNT
  56. FTW_CHDIR = 4, /* Change to current directory while processing it. */
  57. # define FTW_CHDIR FTW_CHDIR
  58. FTW_DEPTH = 8 /* Report files in directory before directory itself.*/
  59. # define FTW_DEPTH FTW_DEPTH
  60. # ifdef __USE_GNU
  61. ,
  62. FTW_ACTIONRETVAL = 16 /* Assume callback to return FTW_* values instead of
  63. zero to continue and non-zero to terminate. */
  64. # define FTW_ACTIONRETVAL FTW_ACTIONRETVAL
  65. # endif
  66. };
  67. #ifdef __USE_GNU
  68. /* Return values from callback functions. */
  69. enum
  70. {
  71. FTW_CONTINUE = 0, /* Continue with next sibling or for FTW_D with the
  72. first child. */
  73. # define FTW_CONTINUE FTW_CONTINUE
  74. FTW_STOP = 1, /* Return from `ftw' or `nftw' with FTW_STOP as return
  75. value. */
  76. # define FTW_STOP FTW_STOP
  77. FTW_SKIP_SUBTREE = 2, /* Only meaningful for FTW_D: Don't walk through the
  78. subtree, instead just continue with its next
  79. sibling. */
  80. # define FTW_SKIP_SUBTREE FTW_SKIP_SUBTREE
  81. FTW_SKIP_SIBLINGS = 3,/* Continue with FTW_DP callback for current directory
  82. (if FTW_DEPTH) and then its siblings. */
  83. # define FTW_SKIP_SIBLINGS FTW_SKIP_SIBLINGS
  84. };
  85. #endif
  86. /* Structure used for fourth argument to callback function for `nftw'. */
  87. struct FTW
  88. {
  89. int base;
  90. int level;
  91. };
  92. #endif /* extended X/Open */
  93. /* Convenient types for callback functions. */
  94. typedef int (*__ftw_func_t) (const char *__filename,
  95. const struct stat *__status, int __flag);
  96. #ifdef __USE_LARGEFILE64
  97. typedef int (*__ftw64_func_t) (const char *__filename,
  98. const struct stat64 *__status, int __flag);
  99. #endif
  100. #ifdef __USE_XOPEN_EXTENDED
  101. typedef int (*__nftw_func_t) (const char *__filename,
  102. const struct stat *__status, int __flag,
  103. struct FTW *__info);
  104. # ifdef __USE_LARGEFILE64
  105. typedef int (*__nftw64_func_t) (const char *__filename,
  106. const struct stat64 *__status,
  107. int __flag, struct FTW *__info);
  108. # endif
  109. #endif
  110. #ifdef __UCLIBC_HAS_FTW__
  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. #endif
  130. #if defined __UCLIBC_HAS_NFTW__ && defined __USE_XOPEN_EXTENDED
  131. /* Call a function on every element in a directory tree. FLAG allows
  132. to specify the behaviour more detailed.
  133. This function is a possible cancellation point and therefore not
  134. marked with __THROW. */
  135. # ifndef __USE_FILE_OFFSET64
  136. extern int nftw (const char *__dir, __nftw_func_t __func, int __descriptors,
  137. int __flag) __nonnull ((1, 2));
  138. # else
  139. # ifdef __REDIRECT
  140. extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func,
  141. int __descriptors, int __flag), nftw64)
  142. __nonnull ((1, 2));
  143. # else
  144. # define nftw nftw64
  145. # endif
  146. # endif
  147. # ifdef __USE_LARGEFILE64
  148. extern int nftw64 (const char *__dir, __nftw64_func_t __func,
  149. int __descriptors, int __flag) __nonnull ((1, 2));
  150. # endif
  151. #endif
  152. __END_DECLS
  153. #endif /* ftw.h */