dirent.in.h 8.1 KB

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