Print this page
reorder rewinddir prototype/define
Build fixes.
opendir, dirfd are in XPG7
alphasort and scandir are new in XPG7


   7  *
   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  */
  21 
  22 /*
  23  * Copyright 2007 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 #ifndef _DIRENT_H
  31 #define _DIRENT_H
  32 
  33 #pragma ident   "%Z%%M% %I%     %E% SMI"        /* SVr4.0 1.6.1.5   */
  34 
  35 #include <sys/feature_tests.h>
  36 
  37 #include <sys/types.h>
  38 #include <sys/dirent.h>
  39 
  40 #ifdef  __cplusplus
  41 extern "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 
  53 typedef 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 
  63 typedef 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 
  72 #if defined(__STDC__)
  73 
  74 /* large file compilation environment setup */
  75 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
  76 #ifdef __PRAGMA_REDEFINE_EXTNAME
  77 #pragma redefine_extname        readdir readdir64
  78 #pragma redefine_extname        scandir scandir64
  79 #pragma redefine_extname        alphasort alphasort64
  80 #else
  81 #define readdir                 readdir64
  82 #define scandir                 scandir64
  83 #define alphasort               alphasort64
  84 #endif
  85 #endif  /* _FILE_OFFSET_BITS == 64 */
  86 
  87 /* In the LP64 compilation environment, all APIs are already large file */
  88 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
  89 #ifdef __PRAGMA_REDEFINE_EXTNAME
  90 #pragma redefine_extname        readdir64       readdir
  91 #pragma redefine_extname        scandir64       scandir
  92 #pragma redefine_extname        alphasort64     alphasort
  93 #else
  94 #define readdir64               readdir
  95 #define scandir64               scandir
  96 #define alphsort64              alphasort
  97 #endif
  98 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
  99 
 100 extern DIR              *opendir(const char *);
 101 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
 102         defined(_ATFILE_SOURCE)
 103 extern DIR              *fdopendir(int);
 104 extern int              dirfd(DIR *);
 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 extern int              dirfd();
 143 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
 144 extern struct dirent    *readdir();
 145 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
 146         defined(_XOPEN_SOURCE)
 147 extern long             telldir();
 148 extern void             seekdir();
 149 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
 150 extern void             rewinddir();
 151 extern int              closedir();
 152 
 153 /* transitional large file interface */
 154 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 155             !defined(__PRAGMA_REDEFINE_EXTNAME))
 156 extern struct dirent64  *readdir64();
 157 #endif
 158 
 159 #endif
 160 
 161 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
 162         defined(_XOPEN_SOURCE)
 163 #define rewinddir(dirp) seekdir(dirp, 0L)
 164 #endif
 165 
 166 /*
 167  * readdir_r() prototype is defined here.
 168  *
 169  * There are several variations, depending on whether compatibility with old
 170  * POSIX draft specifications or the final specification is desired and on
 171  * whether the large file compilation environment is active.  To combat a
 172  * combinatorial explosion, enabling large files implies using the final
 173  * specification (since the definition of the large file environment
 174  * considerably postdates that of the final readdir_r specification).
 175  *
 176  * In the LP64 compilation environment, all APIs are already large file,
 177  * and since there are no 64-bit applications that can have seen the
 178  * draft implementation, again, we use the final POSIX specification.
 179  */
 180 
 181 #if     defined(__EXTENSIONS__) || defined(_REENTRANT) || \
 182         !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
 183         defined(_POSIX_PTHREAD_SEMANTICS)
 184 
 185 #if     defined(__STDC__)
 186 
 187 #if     !defined(_LP64) && _FILE_OFFSET_BITS == 32
 188 
 189 #if     (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 190 
 191 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 192 #pragma redefine_extname readdir_r      __posix_readdir_r
 193 extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
 194                 struct dirent **_RESTRICT_KYWD);
 195 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 196 
 197 extern int __posix_readdir_r(DIR *_RESTRICT_KYWD,
 198     struct dirent *_RESTRICT_KYWD, struct dirent **_RESTRICT_KYWD);
 199 
 200 #ifdef  __lint
 201 #define readdir_r       __posix_readdir_r
 202 #else   /* !__lint */
 203 
 204 static int
 205 readdir_r(DIR *_RESTRICT_KYWD __dp, struct dirent *_RESTRICT_KYWD __ent,
 206                 struct dirent **_RESTRICT_KYWD __res) {


 226 #endif
 227 #else   /* _LP64 */
 228 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 229 #pragma redefine_extname readdir_r      readdir64_r
 230 #else
 231 #define readdir_r               readdir64_r
 232 #endif
 233 #endif  /* _LP64 */
 234 extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
 235         struct dirent **_RESTRICT_KYWD);
 236 
 237 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 32 */
 238 
 239 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 240             !defined(__PRAGMA_REDEFINE_EXTNAME))
 241 /* transitional large file interface */
 242 extern int readdir64_r(DIR *_RESTRICT_KYWD, struct dirent64 *_RESTRICT_KYWD,
 243         struct dirent64 **_RESTRICT_KYWD);
 244 #endif
 245 
 246 #else  /* __STDC__ */
 247 
 248 #if     !defined(_LP64) && _FILE_OFFSET_BITS == 32
 249 
 250 #if     (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 251 
 252 #ifdef __PRAGMA_REDEFINE_EXTNAME
 253 #pragma redefine_extname readdir_r __posix_readdir_r
 254 extern int readdir_r();
 255 #else  /* __PRAGMA_REDEFINE_EXTNAME */
 256 
 257 extern int __posix_readdir_r();
 258 
 259 #ifdef  __lint
 260 #define readdir_r __posix_readdir_r
 261 #else   /* !__lint */
 262 
 263 static int
 264 readdir_r(DIR *_RESTRICT_KYWD __dp, struct dirent *_RESTRICT_KYWD __ent,
 265         struct dirent **_RESTRICT_KYWD __res)
 266 {
 267         return (__posix_readdir_r(__dp, __ent, __res));
 268 }
 269 
 270 #endif /* !__lint */
 271 #endif /* __PRAGMA_REDEFINE_EXTNAME */
 272 
 273 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 274 
 275 extern struct dirent *readdir_r();
 276 
 277 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 278 
 279 #else   /* !_LP64 && _FILE_OFFSET_BITS == 32 */
 280 
 281 #if defined(_LP64)
 282 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 283 #pragma redefine_extname readdir64_r    readdir_r
 284 #else
 285 #define readdir64_r     readdir
 286 #endif
 287 #else   /* _LP64 */
 288 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 289 #pragma redefine_extname readdir_r readdir64_r
 290 #else
 291 #define readdir_r readdir64_r
 292 #endif
 293 #endif  /* _LP64 */
 294 extern int      readdir_r();
 295 
 296 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 32 */
 297 
 298 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 299             !defined(__PRAGMA_REDEFINE_EXTNAME))
 300 /* transitional large file interface */
 301 extern int      readdir64_r();
 302 #endif
 303 
 304 #endif /* __STDC__ */
 305 
 306 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
 307 
 308 #ifdef  __cplusplus
 309 }
 310 #endif
 311 
 312 #endif  /* _DIRENT_H */


   7  *
   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  */
  21 
  22 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  29  */
  30 
  31 /*      Copyright (c) 1988 AT&T     */
  32 /*        All Rights Reserved   */
  33 
  34 #ifndef _DIRENT_H
  35 #define _DIRENT_H
  36 


  37 #include <sys/feature_tests.h>
  38 
  39 #include <sys/types.h>
  40 #include <sys/dirent.h>
  41 
  42 #ifdef  __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 #if !defined(_STRICT_SYMBOLS)

  47 #define MAXNAMLEN       512             /* maximum filename length */
  48 #define DIRBUF          8192            /* buffer size for fs-indep. dirs */
  49 #endif
  50 


  51 #if !defined(__XOPEN_OR_POSIX)
  52 
  53 typedef 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 
  63 typedef 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 


  72 /* 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 
  98 extern DIR              *opendir(const char *);
  99 #if defined(_XPG7) || defined(_ATFILE_SOURCE) || !defined(_STRICT_SYMBOLS)

 100 extern DIR              *fdopendir(int);
 101 extern int              dirfd(DIR *);
 102 #endif
 103 
 104 #if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
 105 extern int              scandir(const char *, struct dirent ***,
 106                                 int (*)(const struct dirent *),
 107                                 int (*)(const struct dirent **,
 108                                         const struct dirent **));
 109 extern int              alphasort(const struct dirent **,
 110                                         const struct dirent **);
 111 #endif
 112 
 113 extern struct dirent    *readdir(DIR *);





 114 extern void             rewinddir(DIR *);
 115 extern int              closedir(DIR *);
 116 
 117 #if defined(_XOPEN_SOURCE) || !defined(_STRICT_SYMBOLS)
 118 extern long             telldir(DIR *);
 119 extern void             seekdir(DIR *, long);
 120 #define rewinddir(dirp) seekdir(dirp, 0L)
 121 #endif
 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(_STRICT_SYMBOLS)
 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 /* !_STRICT_SYMBOLS */
 134 #endif
 135 






























 136 /*
 137  * readdir_r() prototype is defined here.
 138  *
 139  * There are several variations, depending on whether compatibility with old
 140  * POSIX draft specifications or the final specification is desired and on
 141  * whether the large file compilation environment is active.  To combat a
 142  * combinatorial explosion, enabling large files implies using the final
 143  * specification (since the definition of the large file environment
 144  * considerably postdates that of the final readdir_r specification).
 145  *
 146  * In the LP64 compilation environment, all APIs are already large file,
 147  * and since there are no 64-bit applications that can have seen the
 148  * draft implementation, again, we use the final POSIX specification.
 149  */
 150 
 151 #if     defined(__EXTENSIONS__) || defined(_REENTRANT) || \
 152         !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
 153         defined(_POSIX_PTHREAD_SEMANTICS)
 154 


 155 #if     !defined(_LP64) && _FILE_OFFSET_BITS == 32
 156 
 157 #if     (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 158 
 159 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 160 #pragma redefine_extname readdir_r      __posix_readdir_r
 161 extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
 162                 struct dirent **_RESTRICT_KYWD);
 163 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 164 
 165 extern int __posix_readdir_r(DIR *_RESTRICT_KYWD,
 166     struct dirent *_RESTRICT_KYWD, struct dirent **_RESTRICT_KYWD);
 167 
 168 #ifdef  __lint
 169 #define readdir_r       __posix_readdir_r
 170 #else   /* !__lint */
 171 
 172 static int
 173 readdir_r(DIR *_RESTRICT_KYWD __dp, struct dirent *_RESTRICT_KYWD __ent,
 174                 struct dirent **_RESTRICT_KYWD __res) {


 194 #endif
 195 #else   /* _LP64 */
 196 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 197 #pragma redefine_extname readdir_r      readdir64_r
 198 #else
 199 #define readdir_r               readdir64_r
 200 #endif
 201 #endif  /* _LP64 */
 202 extern int readdir_r(DIR *_RESTRICT_KYWD, struct dirent *_RESTRICT_KYWD,
 203         struct dirent **_RESTRICT_KYWD);
 204 
 205 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 32 */
 206 
 207 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 208             !defined(__PRAGMA_REDEFINE_EXTNAME))
 209 /* transitional large file interface */
 210 extern int readdir64_r(DIR *_RESTRICT_KYWD, struct dirent64 *_RESTRICT_KYWD,
 211         struct dirent64 **_RESTRICT_KYWD);
 212 #endif
 213 




























































 214 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
 215 
 216 #ifdef  __cplusplus
 217 }
 218 #endif
 219 
 220 #endif  /* _DIRENT_H */