dirent.in.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* A GNU-like <dirent.h>.
  2. Copyright (C) 2006-2017 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. # define GNULIB_defined_opendir 1
  65. # endif
  66. _GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
  67. _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
  68. # else
  69. # if !@HAVE_OPENDIR@
  70. _GL_FUNCDECL_SYS (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
  71. # endif
  72. _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
  73. # endif
  74. _GL_CXXALIASWARN (opendir);
  75. #elif defined GNULIB_POSIXCHECK
  76. # undef opendir
  77. # if HAVE_RAW_DECL_OPENDIR
  78. _GL_WARN_ON_USE (opendir, "opendir is not portable - "
  79. "use gnulib module opendir for portability");
  80. # endif
  81. #endif
  82. #if @GNULIB_READDIR@
  83. # if !@HAVE_READDIR@
  84. _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  85. # endif
  86. _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp));
  87. _GL_CXXALIASWARN (readdir);
  88. #elif defined GNULIB_POSIXCHECK
  89. # undef readdir
  90. # if HAVE_RAW_DECL_READDIR
  91. _GL_WARN_ON_USE (readdir, "readdir is not portable - "
  92. "use gnulib module readdir for portability");
  93. # endif
  94. #endif
  95. #if @GNULIB_REWINDDIR@
  96. # if !@HAVE_REWINDDIR@
  97. _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  98. # endif
  99. _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp));
  100. _GL_CXXALIASWARN (rewinddir);
  101. #elif defined GNULIB_POSIXCHECK
  102. # undef rewinddir
  103. # if HAVE_RAW_DECL_REWINDDIR
  104. _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
  105. "use gnulib module rewinddir for portability");
  106. # endif
  107. #endif
  108. #if @GNULIB_CLOSEDIR@
  109. # if @REPLACE_CLOSEDIR@
  110. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  111. # undef closedir
  112. # define closedir rpl_closedir
  113. # define GNULIB_defined_closedir 1
  114. # endif
  115. _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  116. _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
  117. # else
  118. # if !@HAVE_CLOSEDIR@
  119. _GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
  120. # endif
  121. _GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
  122. # endif
  123. _GL_CXXALIASWARN (closedir);
  124. #elif defined GNULIB_POSIXCHECK
  125. # undef closedir
  126. # if HAVE_RAW_DECL_CLOSEDIR
  127. _GL_WARN_ON_USE (closedir, "closedir is not portable - "
  128. "use gnulib module closedir for portability");
  129. # endif
  130. #endif
  131. #if @GNULIB_DIRFD@
  132. /* Return the file descriptor associated with the given directory stream,
  133. or -1 if none exists. */
  134. # if @REPLACE_DIRFD@
  135. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  136. # undef dirfd
  137. # define dirfd rpl_dirfd
  138. # endif
  139. _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
  140. _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
  141. # ifdef __KLIBC__
  142. /* Gnulib internal hooks needed to maintain the dirfd metadata. */
  143. _GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp)
  144. _GL_ARG_NONNULL ((2));
  145. _GL_EXTERN_C void _gl_unregister_dirp_fd (int fd);
  146. # endif
  147. # else
  148. # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
  149. /* dirfd is defined as a macro and not as a function.
  150. Turn it into a function and get rid of the macro. */
  151. static inline int (dirfd) (DIR *dp) { return dirfd (dp); }
  152. # undef dirfd
  153. # endif
  154. # if !(@HAVE_DECL_DIRFD@ || defined dirfd)
  155. _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
  156. # endif
  157. _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
  158. # endif
  159. _GL_CXXALIASWARN (dirfd);
  160. #elif defined GNULIB_POSIXCHECK
  161. # undef dirfd
  162. # if HAVE_RAW_DECL_DIRFD
  163. _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
  164. "use gnulib module dirfd for portability");
  165. # endif
  166. #endif
  167. #if @GNULIB_FDOPENDIR@
  168. /* Open a directory stream visiting the given directory file
  169. descriptor. Return NULL and set errno if fd is not visiting a
  170. directory. On success, this function consumes fd (it will be
  171. implicitly closed either by this function or by a subsequent
  172. closedir). */
  173. # if @REPLACE_FDOPENDIR@
  174. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  175. # undef fdopendir
  176. # define fdopendir rpl_fdopendir
  177. # endif
  178. _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
  179. _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
  180. # else
  181. # if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
  182. _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
  183. # endif
  184. _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
  185. # endif
  186. _GL_CXXALIASWARN (fdopendir);
  187. #elif defined GNULIB_POSIXCHECK
  188. # undef fdopendir
  189. # if HAVE_RAW_DECL_FDOPENDIR
  190. _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
  191. "use gnulib module fdopendir for portability");
  192. # endif
  193. #endif
  194. #if @GNULIB_SCANDIR@
  195. /* Scan the directory DIR, calling FILTER on each directory entry.
  196. Entries for which FILTER returns nonzero are individually malloc'd,
  197. sorted using qsort with CMP, and collected in a malloc'd array in
  198. *NAMELIST. Returns the number of entries selected, or -1 on error. */
  199. # if !@HAVE_SCANDIR@
  200. _GL_FUNCDECL_SYS (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_ARG_NONNULL ((1, 2, 4)));
  205. # endif
  206. /* Need to cast, because on glibc systems, the fourth parameter is
  207. int (*cmp) (const void *, const void *). */
  208. _GL_CXXALIAS_SYS_CAST (scandir, int,
  209. (const char *dir, struct dirent ***namelist,
  210. int (*filter) (const struct dirent *),
  211. int (*cmp) (const struct dirent **, const struct dirent **)));
  212. _GL_CXXALIASWARN (scandir);
  213. #elif defined GNULIB_POSIXCHECK
  214. # undef scandir
  215. # if HAVE_RAW_DECL_SCANDIR
  216. _GL_WARN_ON_USE (scandir, "scandir is unportable - "
  217. "use gnulib module scandir for portability");
  218. # endif
  219. #endif
  220. #if @GNULIB_ALPHASORT@
  221. /* Compare two 'struct dirent' entries alphabetically. */
  222. # if !@HAVE_ALPHASORT@
  223. _GL_FUNCDECL_SYS (alphasort, int,
  224. (const struct dirent **, const struct dirent **)
  225. _GL_ATTRIBUTE_PURE
  226. _GL_ARG_NONNULL ((1, 2)));
  227. # endif
  228. /* Need to cast, because on glibc systems, the parameters are
  229. (const void *, const void *). */
  230. _GL_CXXALIAS_SYS_CAST (alphasort, int,
  231. (const struct dirent **, const struct dirent **));
  232. _GL_CXXALIASWARN (alphasort);
  233. #elif defined GNULIB_POSIXCHECK
  234. # undef alphasort
  235. # if HAVE_RAW_DECL_ALPHASORT
  236. _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
  237. "use gnulib module alphasort for portability");
  238. # endif
  239. #endif
  240. #endif /* _@GUARD_PREFIX@_DIRENT_H */
  241. #endif /* _@GUARD_PREFIX@_DIRENT_H */