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