1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#ifndef _DIRENT_H
#define _DIRENT_H
#include <sys/feature_tests.h>
#include <sys/types.h>
#include <sys/dirent.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
#define MAXNAMLEN 512 /* maximum filename length */
#define DIRBUF 8192 /* buffer size for fs-indep. dirs */
#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
#if !defined(__XOPEN_OR_POSIX)
typedef struct {
int dd_fd; /* file descriptor */
int dd_loc; /* offset in block */
int dd_size; /* amount of valid data */
char *dd_buf; /* directory block */
} DIR; /* stream data from opendir() */
#else
typedef struct {
int d_fd; /* file descriptor */
int d_loc; /* offset in block */
int d_size; /* amount of valid data */
char *d_buf; /* directory block */
} DIR; /* stream data from opendir() */
#endif /* !defined(__XOPEN_OR_POSIX) */
/* large file compilation environment setup */
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname readdir readdir64
#pragma redefine_extname scandir scandir64
#pragma redefine_extname alphasort alphasort64
#else
#define readdir readdir64
#define scandir scandir64
#define alphasort alphasort64
#endif
#endif /* _FILE_OFFSET_BITS == 64 */
/* In the LP64 compilation environment, all APIs are already large file */
#if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname readdir64 readdir
#pragma redefine_extname scandir64 scandir
#pragma redefine_extname alphasort64 alphasort
#else
#define readdir64 readdir
#define scandir64 scandir
#define alphsort64 alphasort
#endif
#endif /* _LP64 && _LARGEFILE64_SOURCE */
extern DIR *opendir(const char *);
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
defined(_ATFILE_SOURCE)
extern DIR *fdopendir(int);
extern int dirfd(DIR *);
#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
extern int scandir(const char *, struct dirent *(*[]),
int (*)(const struct dirent *),
int (*)(const struct dirent **,
const struct dirent **));
extern int alphasort(const struct dirent **,
const struct dirent **);
#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
extern struct dirent *readdir(DIR *);
#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
defined(_XOPEN_SOURCE)
extern long telldir(DIR *);
extern void seekdir(DIR *, long);
#endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
extern void rewinddir(DIR *);
extern int closedir(DIR *);
/* transitional large file interface */
#if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
!defined(__PRAGMA_REDEFINE_EXTNAME))
extern struct dirent64 *readdir64(DIR *);
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
extern int scandir64(const char *, struct dirent64 *(*[]),
int (*)(const struct dirent64 *),
int (*)(const struct dirent64 **,
const struct dirent64 **));
extern int alphasort64(const struct dirent64 **, const struct dirent64 **);
#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
#endif
#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
defined(_XOPEN_SOURCE)
#define rewinddir(dirp) seekdir(dirp, 0L)
#endif
/*
* readdir_r() prototype is defined here.
*
* There are several variations, depending on whether compatibility with old
* POSIX draft specifications or the final specification is desired and on
* whether the large file compilation environment is active. To combat a
* combinatorial explosion, enabling large files implies using the final
* specification (since the definition of the large file environment
* considerably postdates that of the final readdir_r specification).
*
* In the LP64 compilation environment, all APIs are already large file,
* and since there are no 64-bit applications that can have seen the
* draft implementation, again, we use the final POSIX specification.
*/
#if defined(__EXTENSIONS__) || defined(_REENTRANT) || \
!defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
defined(_POSIX_PTHREAD_SEMANTICS)
#if !defined(_LP64) && _FILE_OFFSET_BITS == 32
#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname readdir_r __posix_readdir_r
extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
struct dirent **_RESTRICT_KYWD);
#else /* __PRAGMA_REDEFINE_EXTNAME */
extern int __posix_readdir_r(DIR *_RESTRICT_KYWD,
struct dirent *_RESTRICT_KYWD, struct dirent **_RESTRICT_KYWD);
#ifdef __lint
#define readdir_r __posix_readdir_r
#else /* !__lint */
static int
readdir_r(DIR *_RESTRICT_KYWD __dp, struct dirent *_RESTRICT_KYWD __ent,
struct dirent **_RESTRICT_KYWD __res) {
return (__posix_readdir_r(__dp, __ent, __res));
}
#endif /* !__lint */
#endif /* __PRAGMA_REDEFINE_EXTNAME */
#else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
extern struct dirent *readdir_r(DIR *__dp, struct dirent *__ent);
#endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
#else /* !_LP64 && _FILE_OFFSET_BITS == 32 */
#if defined(_LP64)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname readdir64_r readdir_r
#else
#define readdir64_r readdir_r
#endif
#else /* _LP64 */
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname readdir_r readdir64_r
#else
#define readdir_r readdir64_r
#endif
#endif /* _LP64 */
extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
struct dirent **_RESTRICT_KYWD);
#endif /* !_LP64 && _FILE_OFFSET_BITS == 32 */
#if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
!defined(__PRAGMA_REDEFINE_EXTNAME))
/* transitional large file interface */
extern int readdir64_r(DIR *_RESTRICT_KYWD, struct dirent64 *_RESTRICT_KYWD,
struct dirent64 **_RESTRICT_KYWD);
#endif
#endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
#ifdef __cplusplus
}
#endif
#endif /* _DIRENT_H */
|