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