1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * POSIX Standard: 5.1.2 Directory Operations <dirent.h>
30 #include <gnu/types.h>
36 /* Directory entry structure. */
39 __ino_t d_fileno; /* File serial number. */
40 size_t d_namlen; /* Length of the file name. */
42 /* Only this member is in the POSIX standard. */
43 char d_name[1]; /* File name (actually longer). */
46 #if defined(__USE_BSD) || defined(__USE_MISC)
47 #define d_ino d_fileno/* Backward compatibility. */
50 /* Directory stream type. */
53 int __fd; /* File descriptor. */
55 char *__data; /* Directory block. */
56 size_t __allocation; /* Space allocated for the block. */
57 size_t __offset; /* Current offset into the block. */
58 size_t __size; /* Total valid data in the block. */
60 struct dirent __entry; /* Returned by `readdir'. */
64 /* Open a directory stream on NAME.
65 Return a DIR stream on the directory, or NULL if it could not be opened. */
66 extern DIR *opendir __P ((__const char *__name));
68 /* Close the directory stream DIRP.
69 Return 0 if successful, -1 if not. */
70 extern int closedir __P ((DIR * __dirp));
72 /* Read a directory entry from DIRP.
73 Return a pointer to a `struct dirent' describing the entry,
74 or NULL for EOF or error. The storage returned may be overwritten
75 by a later readdir call on the same DIR stream. */
76 extern struct dirent *readdir __P ((DIR * __dirp));
78 /* Rewind DIRP to the beginning of the directory. */
79 extern void rewinddir __P ((DIR * __dirp));
81 #if defined(__USE_BSD) || defined(__USE_MISC)
84 /* Get the definitions of the POSIX.1 limits. */
85 #include <posix1_lim.h>
87 /* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'. */
89 #define MAXNAMLEN NAME_MAX
95 #include <gnu/types.h>
97 /* Seek to position POS on DIRP. */
98 extern void seekdir __P ((DIR * __dirp, __off_t __pos));
100 /* Return the current position of DIRP. */
101 extern __off_t telldir __P ((DIR * __dirp));
103 /* Scan the directory DIR, calling SELECT on each directory entry.
104 Entries for which SELECT returns nonzero are individually malloc'd,
105 sorted using qsort with CMP, and collected in a malloc'd array in
106 *NAMELIST. Returns the number of entries selected, or -1 on error. */
107 extern int scandir __P ((__const char *__dir,
108 struct dirent *** __namelist,
109 int (*__select) __P ((struct dirent *)),
110 int (*__cmp) __P ((__const __ptr_t, __const __ptr_t))));
112 /* Function to compare two `struct dirent's alphabetically. */
113 extern int alphasort __P ((__const __ptr_t, __const __ptr_t));
116 /* Read directory entries from FD into BUF, reading at most NBYTES.
117 Reading starts at offset *BASEP, and *BASEP is updated with the new
118 position after reading. Returns the number of bytes read; zero when at
119 end of directory; or -1 for errors. */
120 extern __ssize_t __getdirentries __P ((int __fd, char *__buf,
121 size_t __nbytes, __off_t * __basep));
122 extern __ssize_t getdirentries __P ((int __fd, char *__buf,
123 size_t __nbytes, __off_t * __basep));
126 #endif /* Use BSD or misc. */
130 #endif /* dirent.h */