dirent.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (C) 1991, 1992 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. /*
  16. * POSIX Standard: 5.1.2 Directory Operations <dirent.h>
  17. */
  18. #ifndef _DIRENT_H
  19. #define _DIRENT_H 1
  20. #include <features.h>
  21. __BEGIN_DECLS
  22. #include <gnu/types.h>
  23. #define __need_size_t
  24. #include <stddef.h>
  25. #include <sys/types.h>
  26. #include <linux/limits.h>
  27. #include <linux/dirent.h>
  28. #if defined(__USE_GNU)
  29. #define d_fileno d_ino /* glibc compatibility. */
  30. #if 0
  31. #define d_namlen d_reclen /* glibc compatibility. */
  32. #endif
  33. #endif
  34. #if defined(DIRENT_ILLEGAL_ACCESS) || \
  35. (defined(__SVR4_I386_ABI_L1__) && !defined(INTERNAL_LINUX_C_LIB))
  36. /* Use it at your own risk. */
  37. typedef struct DIR
  38. {
  39. /* file descriptor */
  40. int dd_fd;
  41. /* offset of the next dir entry in buffer */
  42. off_t dd_loc;
  43. /* bytes of valid entries in buffer */
  44. size_t dd_size;
  45. /* -> directory buffer */
  46. struct dirent *dd_buf;
  47. } DIR;
  48. #else
  49. /* The internal is hidden from the user. */
  50. typedef struct DIR DIR;
  51. #endif
  52. /* Open a directory stream on NAME.
  53. Return a DIR stream on the directory, or NULL if it could not be opened. */
  54. extern DIR *opendir __P ((__const char *__name));
  55. /* Close the directory stream DIRP.
  56. Return 0 if successful, -1 if not. */
  57. extern int closedir __P ((DIR * __dirp));
  58. /* Read a directory entry from DIRP.
  59. Return a pointer to a `struct dirent' describing the entry,
  60. or NULL for EOF or error. The storage returned may be overwritten
  61. by a later readdir call on the same DIR stream. */
  62. extern struct dirent *readdir __P ((DIR * __dirp));
  63. /* Rewind DIRP to the beginning of the directory. */
  64. extern void rewinddir __P ((DIR * __dirp));
  65. #if defined(__USE_BSD) || defined(__USE_MISC)
  66. #ifndef MAXNAMLEN
  67. /* Get the definitions of the POSIX.1 limits. */
  68. #include <posix1_lim.h>
  69. /* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'. */
  70. #ifdef NAME_MAX
  71. #define MAXNAMLEN NAME_MAX
  72. #else
  73. #define MAXNAMLEN 255
  74. #endif
  75. #endif
  76. #include <gnu/types.h>
  77. /* Seek to position POS on DIRP. */
  78. extern void seekdir __P ((DIR * __dirp, __off_t __pos));
  79. /* Return the current position of DIRP. */
  80. extern __off_t telldir __P ((DIR * __dirp));
  81. typedef int (*__dir_select_fn_t) __P ((__const struct dirent *));
  82. typedef int (*__dir_compar_fn_t) __P ((
  83. __const struct dirent * __const *,
  84. __const struct dirent * __const *
  85. ));
  86. /* Scan the directory DIR, calling SELECT on each directory entry.
  87. Entries for which SELECT returns nonzero are individually malloc'd,
  88. sorted using qsort with CMP, and collected in a malloc'd array in
  89. *NAMELIST. Returns the number of entries selected, or -1 on error. */
  90. extern int scandir __P ((__const char *__dir,
  91. struct dirent ***__namelist,
  92. __dir_select_fn_t __dir_select_fn,
  93. __dir_compar_fn_t __dir_compar_fn));
  94. /* Function to compare two `struct dirent's alphabetically. */
  95. extern int alphasort __P ((
  96. __const struct dirent * __const *,
  97. __const struct dirent * __const *
  98. ));
  99. /* Read directory entries from FD into BUF, reading at most NBYTES.
  100. Reading starts at offset *BASEP, and *BASEP is updated with the new
  101. position after reading. Returns the number of bytes read; zero when at
  102. end of directory; or -1 for errors. */
  103. extern __ssize_t __getdirentries __P ((int __fd, char *__buf,
  104. size_t __nbytes, __off_t *__basep));
  105. extern __ssize_t getdirentries __P ((int __fd, char *__buf,
  106. size_t __nbytes, __off_t *__basep));
  107. extern int dirfd __P ((DIR *__dirp));
  108. #endif /* Use BSD or misc. */
  109. #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_REENTRANT)
  110. extern int readdir_r __P((DIR *__dirp, struct dirent *__entry,
  111. struct dirent **__result));
  112. #endif
  113. __END_DECLS
  114. #endif /* dirent.h */