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

@@ -22,34 +22,34 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2014 Garrett D'Amore <garrett@damore.org>
+ */
+
 /*      Copyright (c) 1988 AT&T */
 /*        All Rights Reserved   */
 
 #ifndef _DIRENT_H
 #define _DIRENT_H
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"        /* SVr4.0 1.6.1.5   */
-
 #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)
-
+#if !defined(_STRICT_SYMBOLS)
 #define MAXNAMLEN       512             /* maximum filename length */
 #define DIRBUF          8192            /* buffer size for fs-indep. dirs */
+#endif
 
-#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 */

@@ -67,12 +67,10 @@
         char    *d_buf;         /* directory block */
 } DIR;                          /* stream data from opendir() */
 
 #endif /* !defined(__XOPEN_OR_POSIX) */
 
-#if defined(__STDC__)
-
 /* 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

@@ -96,75 +94,47 @@
 #define alphsort64              alphasort
 #endif
 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
 
 extern DIR              *opendir(const char *);
-#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
-        defined(_ATFILE_SOURCE)
+#if defined(_XPG7) || defined(_ATFILE_SOURCE) || !defined(_STRICT_SYMBOLS)
 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 *(*[]),
+#endif
+
+#if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
+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) */
+#endif
+
 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 *);
 
+#if defined(_XOPEN_SOURCE) || !defined(_STRICT_SYMBOLS)
+extern long             telldir(DIR *);
+extern void             seekdir(DIR *, long);
+#define rewinddir(dirp) seekdir(dirp, 0L)
+#endif
+
 /* 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 *(*[]),
+#if !defined(_STRICT_SYMBOLS)
+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 /* !_STRICT_SYMBOLS */
 #endif
 
-#else
-
-extern DIR              *opendir();
-#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
-        defined(_ATFILE_SOURCE)
-extern DIR              *fdopendir();
-extern int              dirfd();
-#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
-extern struct dirent    *readdir();
-#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
-        defined(_XOPEN_SOURCE)
-extern long             telldir();
-extern void             seekdir();
-#endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
-extern void             rewinddir();
-extern int              closedir();
-
-/* transitional large file interface */
-#if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
-            !defined(__PRAGMA_REDEFINE_EXTNAME))
-extern struct dirent64  *readdir64();
-#endif
-
-#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

@@ -180,12 +150,10 @@
 
 #if     defined(__EXTENSIONS__) || defined(_REENTRANT) || \
         !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
         defined(_POSIX_PTHREAD_SEMANTICS)
 
-#if     defined(__STDC__)
-
 #if     !defined(_LP64) && _FILE_OFFSET_BITS == 32
 
 #if     (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 
 #ifdef  __PRAGMA_REDEFINE_EXTNAME

@@ -241,70 +209,10 @@
 /* transitional large file interface */
 extern int readdir64_r(DIR *_RESTRICT_KYWD, struct dirent64 *_RESTRICT_KYWD,
         struct dirent64 **_RESTRICT_KYWD);
 #endif
 
-#else  /* __STDC__ */
-
-#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();
-#else  /* __PRAGMA_REDEFINE_EXTNAME */
-
-extern int __posix_readdir_r();
-
-#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();
-
-#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
-#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();
-
-#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();
-#endif
-
-#endif /* __STDC__ */
-
 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
 
 #ifdef  __cplusplus
 }
 #endif