dirent.in.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* A GNU-like <dirent.h>.
  2. Copyright (C) 2006-2014 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program 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
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef _@GUARD_PREFIX@_DIRENT_H
  14. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. @PRAGMA_COLUMNS@
  18. /* The include_next requires a split double-inclusion guard. */
  19. #if @HAVE_DIRENT_H@
  20. # @INCLUDE_NEXT@ @NEXT_DIRENT_H@
  21. #endif
  22. #ifndef _@GUARD_PREFIX@_DIRENT_H
  23. #define _@GUARD_PREFIX@_DIRENT_H
  24. /* Get ino_t. Needed on some systems, including glibc 2.8. */
  25. #include <sys/types.h>
  26. #if !@HAVE_DIRENT_H@
  27. /* Define types DIR and 'struct dirent'. */
  28. # if !GNULIB_defined_struct_dirent
  29. struct dirent
  30. {
  31. char d_type;
  32. char d_name[1];
  33. };
  34. /* Possible values for 'd_type'. */
  35. # define DT_UNKNOWN 0
  36. # define DT_FIFO 1 /* FIFO */
  37. # define DT_CHR 2 /* character device */
  38. # define DT_DIR 4 /* directory */
  39. # define DT_BLK 6 /* block device */
  40. # define DT_REG 8 /* regular file */
  41. # define DT_LNK 10 /* symbolic link */
  42. # define DT_SOCK 12 /* socket */
  43. # define DT_WHT 14 /* whiteout */
  44. typedef struct gl_directory DIR;
  45. # define GNULIB_defined_struct_dirent 1
  46. # endif
  47. #endif
  48. /* The __attribute__ feature is available in gcc versions 2.5 and later.
  49. The attribute __pure__ was added in gcc 2.96. */
  50. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  51. # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
  52. #else
  53. # define _GL_ATTRIBUTE_PURE /* empty */
  54. #endif
  55. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  56. /* The definition of _GL_ARG_NONNULL is copied here. */
  57. /* The definition of _GL_WARN_ON_USE is copied here. */
  58. /* Declare overridden functions. */
  59. #if @GNULIB_OPENDIR@
  60. # if @REPLACE_OPENDIR@
  61. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  62. # undef opendir
  63. # define opendir rpl_opendir
  64. # endif
  65. _GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
  66. _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
  67. # else
  68. # if !@HAVE_OPENDIR@
  69. _GL_FUNCDECL_SYS (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
  70. # endif
  71. _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
  72. # endif
  73. _GL_CXXALIASWARN (opendir);
  74. #elif defined GNULIB_POSIXCHECK
  75. # undef opendir
  76. # if HAVE_RAW_DECL_OPENDIR
  77. _GL_WARN_ON_USE (opendir, "opendir is not portable - "
  78. "use gnulib module opendir for portability");
  79. # endif
  80. #endif
  81. #if @GNULIB_READDIR@
  82. # if !@HAVE_READDIR@
  83. _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  84. # endif
  85. _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp));
  86. _GL_CXXALIASWARN (readdir);
  87. #elif defined GNULIB_POSIXCHECK
  88. # undef readdir
  89. # if HAVE_RAW_DECL_READDIR
  90. _GL_WARN_ON_USE (readdir, "readdir is not portable - "
  91. "use gnulib module readdir for portability");
  92. # endif
  93. #endif
  94. #if @GNULIB_REWINDDIR@
  95. # if !@HAVE_REWINDDIR@
  96. _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  97. # endif
  98. _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp));
  99. _GL_CXXALIASWARN (rewinddir);
  100. #elif defined GNULIB_POSIXCHECK
  101. # undef rewinddir
  102. # if HAVE_RAW_DECL_REWINDDIR
  103. _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
  104. "use gnulib module rewinddir for portability");
  105. # endif
  106. #endif
  107. #if @GNULIB_CLOSEDIR@
  108. # if @REPLACE_CLOSEDIR@
  109. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  110. # undef closedir
  111. # define closedir rpl_closedir
  112. # endif
  113. _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  114. _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
  115. # else
  116. # if !@HAVE_CLOSEDIR@
  117. _GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  118. # endif
  119. _GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
  120. # endif
  121. _GL_CXXALIASWARN (closedir);
  122. #elif defined GNULIB_POSIXCHECK
  123. # undef closedir
  124. # if HAVE_RAW_DECL_CLOSEDIR
  125. _GL_WARN_ON_USE (closedir, "closedir is not portable - "
  126. "use gnulib module closedir for portability");
  127. # endif
  128. #endif
  129. #if @GNULIB_DIRFD@
  130. /* Return the file descriptor associated with the given directory stream,
  131. or -1 if none exists. */
  132. # if @REPLACE_DIRFD@
  133. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  134. # undef dirfd
  135. # define dirfd rpl_dirfd
  136. # endif
  137. _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
  138. _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
  139. # else
  140. # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
  141. /* dirfd is defined as a macro and not as a function.
  142. Turn it into a function and get rid of the macro. */
  143. static inline int (dirfd) (DIR *dp) { return dirfd (dp); }
  144. # undef dirfd
  145. # endif
  146. # if !(@HAVE_DECL_DIRFD@ || defined dirfd)
  147. _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
  148. # endif
  149. _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
  150. # endif
  151. _GL_CXXALIASWARN (dirfd);
  152. #elif defined GNULIB_POSIXCHECK
  153. # undef dirfd
  154. # if HAVE_RAW_DECL_DIRFD
  155. _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
  156. "use gnulib module dirfd for portability");
  157. # endif
  158. #endif
  159. #if @GNULIB_FDOPENDIR@
  160. /* Open a directory stream visiting the given directory file
  161. descriptor. Return NULL and set errno if fd is not visiting a
  162. directory. On success, this function consumes fd (it will be
  163. implicitly closed either by this function or by a subsequent
  164. closedir). */
  165. # if @REPLACE_FDOPENDIR@
  166. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  167. # undef fdopendir
  168. # define fdopendir rpl_fdopendir
  169. # endif
  170. _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
  171. _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
  172. # else
  173. # if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
  174. _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
  175. # endif
  176. _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
  177. # endif
  178. _GL_CXXALIASWARN (fdopendir);
  179. #elif defined GNULIB_POSIXCHECK
  180. # undef fdopendir
  181. # if HAVE_RAW_DECL_FDOPENDIR
  182. _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
  183. "use gnulib module fdopendir for portability");
  184. # endif
  185. #endif
  186. #if @GNULIB_SCANDIR@
  187. /* Scan the directory DIR, calling FILTER on each directory entry.
  188. Entries for which FILTER returns nonzero are individually malloc'd,
  189. sorted using qsort with CMP, and collected in a malloc'd array in
  190. *NAMELIST. Returns the number of entries selected, or -1 on error. */
  191. # if !@HAVE_SCANDIR@
  192. _GL_FUNCDECL_SYS (scandir, int,
  193. (const char *dir, struct dirent ***namelist,
  194. int (*filter) (const struct dirent *),
  195. int (*cmp) (const struct dirent **, const struct dirent **))
  196. _GL_ARG_NONNULL ((1, 2, 4)));
  197. # endif
  198. /* Need to cast, because on glibc systems, the fourth parameter is
  199. int (*cmp) (const void *, const void *). */
  200. _GL_CXXALIAS_SYS_CAST (scandir, int,
  201. (const char *dir, struct dirent ***namelist,
  202. int (*filter) (const struct dirent *),
  203. int (*cmp) (const struct dirent **, const struct dirent **)));
  204. _GL_CXXALIASWARN (scandir);
  205. #elif defined GNULIB_POSIXCHECK
  206. # undef scandir
  207. # if HAVE_RAW_DECL_SCANDIR
  208. _GL_WARN_ON_USE (scandir, "scandir is unportable - "
  209. "use gnulib module scandir for portability");
  210. # endif
  211. #endif
  212. #if @GNULIB_ALPHASORT@
  213. /* Compare two 'struct dirent' entries alphabetically. */
  214. # if !@HAVE_ALPHASORT@
  215. _GL_FUNCDECL_SYS (alphasort, int,
  216. (const struct dirent **, const struct dirent **)
  217. _GL_ATTRIBUTE_PURE
  218. _GL_ARG_NONNULL ((1, 2)));
  219. # endif
  220. /* Need to cast, because on glibc systems, the parameters are
  221. (const void *, const void *). */
  222. _GL_CXXALIAS_SYS_CAST (alphasort, int,
  223. (const struct dirent **, const struct dirent **));
  224. _GL_CXXALIASWARN (alphasort);
  225. #elif defined GNULIB_POSIXCHECK
  226. # undef alphasort
  227. # if HAVE_RAW_DECL_ALPHASORT
  228. _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
  229. "use gnulib module alphasort for portability");
  230. # endif
  231. #endif
  232. #endif /* _@GUARD_PREFIX@_DIRENT_H */
  233. #endif /* _@GUARD_PREFIX@_DIRENT_H */