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