17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5289b68b2Sraf * Common Development and Distribution License (the "License"). 6289b68b2Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21289b68b2Sraf 227c478bd9Sstevel@tonic-gate /* 23*ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24*ba3594baSGarrett D'Amore * 25289b68b2Sraf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 307c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifndef _DIRENT_H 337c478bd9Sstevel@tonic-gate #define _DIRENT_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <sys/types.h> 387c478bd9Sstevel@tonic-gate #include <sys/dirent.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 417c478bd9Sstevel@tonic-gate extern "C" { 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define MAXNAMLEN 512 /* maximum filename length */ 477c478bd9Sstevel@tonic-gate #define DIRBUF 8192 /* buffer size for fs-indep. dirs */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate typedef struct { 547c478bd9Sstevel@tonic-gate int dd_fd; /* file descriptor */ 557c478bd9Sstevel@tonic-gate int dd_loc; /* offset in block */ 567c478bd9Sstevel@tonic-gate int dd_size; /* amount of valid data */ 577c478bd9Sstevel@tonic-gate char *dd_buf; /* directory block */ 587c478bd9Sstevel@tonic-gate } DIR; /* stream data from opendir() */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate #else 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate typedef struct { 647c478bd9Sstevel@tonic-gate int d_fd; /* file descriptor */ 657c478bd9Sstevel@tonic-gate int d_loc; /* offset in block */ 667c478bd9Sstevel@tonic-gate int d_size; /* amount of valid data */ 677c478bd9Sstevel@tonic-gate char *d_buf; /* directory block */ 687c478bd9Sstevel@tonic-gate } DIR; /* stream data from opendir() */ 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* large file compilation environment setup */ 737c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 747c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 757c478bd9Sstevel@tonic-gate #pragma redefine_extname readdir readdir64 767c478bd9Sstevel@tonic-gate #pragma redefine_extname scandir scandir64 777c478bd9Sstevel@tonic-gate #pragma redefine_extname alphasort alphasort64 787c478bd9Sstevel@tonic-gate #else 797c478bd9Sstevel@tonic-gate #define readdir readdir64 807c478bd9Sstevel@tonic-gate #define scandir scandir64 817c478bd9Sstevel@tonic-gate #define alphasort alphasort64 827c478bd9Sstevel@tonic-gate #endif 837c478bd9Sstevel@tonic-gate #endif /* _FILE_OFFSET_BITS == 64 */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* In the LP64 compilation environment, all APIs are already large file */ 867c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 877c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 887c478bd9Sstevel@tonic-gate #pragma redefine_extname readdir64 readdir 897c478bd9Sstevel@tonic-gate #pragma redefine_extname scandir64 scandir 907c478bd9Sstevel@tonic-gate #pragma redefine_extname alphasort64 alphasort 917c478bd9Sstevel@tonic-gate #else 927c478bd9Sstevel@tonic-gate #define readdir64 readdir 937c478bd9Sstevel@tonic-gate #define scandir64 scandir 947c478bd9Sstevel@tonic-gate #define alphsort64 alphasort 957c478bd9Sstevel@tonic-gate #endif 967c478bd9Sstevel@tonic-gate #endif /* _LP64 && _LARGEFILE64_SOURCE */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate extern DIR *opendir(const char *); 997c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \ 1007c478bd9Sstevel@tonic-gate defined(_ATFILE_SOURCE) 1017c478bd9Sstevel@tonic-gate extern DIR *fdopendir(int); 102289b68b2Sraf extern int dirfd(DIR *); 1037c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */ 1047c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) 1057c478bd9Sstevel@tonic-gate extern int scandir(const char *, struct dirent *(*[]), 1067c478bd9Sstevel@tonic-gate int (*)(const struct dirent *), 1077c478bd9Sstevel@tonic-gate int (*)(const struct dirent **, 1087c478bd9Sstevel@tonic-gate const struct dirent **)); 1097c478bd9Sstevel@tonic-gate extern int alphasort(const struct dirent **, 1107c478bd9Sstevel@tonic-gate const struct dirent **); 1117c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */ 1127c478bd9Sstevel@tonic-gate extern struct dirent *readdir(DIR *); 1137c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \ 1147c478bd9Sstevel@tonic-gate defined(_XOPEN_SOURCE) 1157c478bd9Sstevel@tonic-gate extern long telldir(DIR *); 1167c478bd9Sstevel@tonic-gate extern void seekdir(DIR *, long); 1177c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */ 1187c478bd9Sstevel@tonic-gate extern void rewinddir(DIR *); 1197c478bd9Sstevel@tonic-gate extern int closedir(DIR *); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* transitional large file interface */ 1227c478bd9Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 1237c478bd9Sstevel@tonic-gate !defined(__PRAGMA_REDEFINE_EXTNAME)) 1247c478bd9Sstevel@tonic-gate extern struct dirent64 *readdir64(DIR *); 1257c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) 1267c478bd9Sstevel@tonic-gate extern int scandir64(const char *, struct dirent64 *(*[]), 1277c478bd9Sstevel@tonic-gate int (*)(const struct dirent64 *), 1287c478bd9Sstevel@tonic-gate int (*)(const struct dirent64 **, 1297c478bd9Sstevel@tonic-gate const struct dirent64 **)); 1307c478bd9Sstevel@tonic-gate extern int alphasort64(const struct dirent64 **, const struct dirent64 **); 1317c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */ 1327c478bd9Sstevel@tonic-gate #endif 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \ 1357c478bd9Sstevel@tonic-gate defined(_XOPEN_SOURCE) 1367c478bd9Sstevel@tonic-gate #define rewinddir(dirp) seekdir(dirp, 0L) 1377c478bd9Sstevel@tonic-gate #endif 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * readdir_r() prototype is defined here. 1417c478bd9Sstevel@tonic-gate * 1427c478bd9Sstevel@tonic-gate * There are several variations, depending on whether compatibility with old 1437c478bd9Sstevel@tonic-gate * POSIX draft specifications or the final specification is desired and on 1447c478bd9Sstevel@tonic-gate * whether the large file compilation environment is active. To combat a 1457c478bd9Sstevel@tonic-gate * combinatorial explosion, enabling large files implies using the final 1467c478bd9Sstevel@tonic-gate * specification (since the definition of the large file environment 1477c478bd9Sstevel@tonic-gate * considerably postdates that of the final readdir_r specification). 1487c478bd9Sstevel@tonic-gate * 1497c478bd9Sstevel@tonic-gate * In the LP64 compilation environment, all APIs are already large file, 1507c478bd9Sstevel@tonic-gate * and since there are no 64-bit applications that can have seen the 1517c478bd9Sstevel@tonic-gate * draft implementation, again, we use the final POSIX specification. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_REENTRANT) || \ 1557c478bd9Sstevel@tonic-gate !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \ 1567c478bd9Sstevel@tonic-gate defined(_POSIX_PTHREAD_SEMANTICS) 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 32 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 1637c478bd9Sstevel@tonic-gate #pragma redefine_extname readdir_r __posix_readdir_r 1647c478bd9Sstevel@tonic-gate extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD, 1657c478bd9Sstevel@tonic-gate struct dirent **_RESTRICT_KYWD); 1667c478bd9Sstevel@tonic-gate #else /* __PRAGMA_REDEFINE_EXTNAME */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate extern int __posix_readdir_r(DIR *_RESTRICT_KYWD, 1697c478bd9Sstevel@tonic-gate struct dirent *_RESTRICT_KYWD, struct dirent **_RESTRICT_KYWD); 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #ifdef __lint 1727c478bd9Sstevel@tonic-gate #define readdir_r __posix_readdir_r 1737c478bd9Sstevel@tonic-gate #else /* !__lint */ 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate static int 1767c478bd9Sstevel@tonic-gate readdir_r(DIR *_RESTRICT_KYWD __dp, struct dirent *_RESTRICT_KYWD __ent, 1777c478bd9Sstevel@tonic-gate struct dirent **_RESTRICT_KYWD __res) { 1787c478bd9Sstevel@tonic-gate return (__posix_readdir_r(__dp, __ent, __res)); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #endif /* !__lint */ 1827c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate extern struct dirent *readdir_r(DIR *__dp, struct dirent *__ent); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #else /* !_LP64 && _FILE_OFFSET_BITS == 32 */ 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #if defined(_LP64) 1937c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 1947c478bd9Sstevel@tonic-gate #pragma redefine_extname readdir64_r readdir_r 1957c478bd9Sstevel@tonic-gate #else 1967c478bd9Sstevel@tonic-gate #define readdir64_r readdir_r 1977c478bd9Sstevel@tonic-gate #endif 1987c478bd9Sstevel@tonic-gate #else /* _LP64 */ 1997c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 2007c478bd9Sstevel@tonic-gate #pragma redefine_extname readdir_r readdir64_r 2017c478bd9Sstevel@tonic-gate #else 2027c478bd9Sstevel@tonic-gate #define readdir_r readdir64_r 2037c478bd9Sstevel@tonic-gate #endif 2047c478bd9Sstevel@tonic-gate #endif /* _LP64 */ 2057c478bd9Sstevel@tonic-gate extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD, 2067c478bd9Sstevel@tonic-gate struct dirent **_RESTRICT_KYWD); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #endif /* !_LP64 && _FILE_OFFSET_BITS == 32 */ 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 2117c478bd9Sstevel@tonic-gate !defined(__PRAGMA_REDEFINE_EXTNAME)) 2127c478bd9Sstevel@tonic-gate /* transitional large file interface */ 2137c478bd9Sstevel@tonic-gate extern int readdir64_r(DIR *_RESTRICT_KYWD, struct dirent64 *_RESTRICT_KYWD, 2147c478bd9Sstevel@tonic-gate struct dirent64 **_RESTRICT_KYWD); 2157c478bd9Sstevel@tonic-gate #endif 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */ 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate #endif 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate #endif /* _DIRENT_H */ 224