OSDN Git Service

Scrub up some lingering problems preventing readdir64 from working
authorEric Andersen <andersen@codepoet.org>
Wed, 14 Nov 2001 11:09:46 +0000 (11:09 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 14 Nov 2001 11:09:46 +0000 (11:09 -0000)
and creating several *64 problems, particualrly when client apps
used -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64.  All better now.
 -Erik

20 files changed:
libc/misc/dirent/alphasort.c
libc/misc/dirent/alphasort64.c
libc/misc/dirent/closedir.c
libc/misc/dirent/dirfd.c
libc/misc/dirent/dirstream.h
libc/misc/dirent/opendir.c
libc/misc/dirent/readdir64.c
libc/misc/dirent/rewinddir.c
libc/misc/dirent/scandir.c
libc/misc/dirent/scandir64.c
libc/misc/dirent/seekdir.c
libc/misc/dirent/telldir.c
libc/sysdeps/linux/arm/bits/dirent.h
libc/sysdeps/linux/i386/bits/dirent.h
libc/sysdeps/linux/m68k/bits/dirent.h
libc/sysdeps/linux/mips/bits/dirent.h
libc/sysdeps/linux/powerpc/bits/dirent.h
libc/sysdeps/linux/sh/bits/dirent.h
libc/sysdeps/linux/sparc/bits/dirent.h
libc/sysdeps/linux/v850/bits/dirent.h

index d7a1d8d..dcf9700 100644 (file)
@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <string.h>
 #include "dirstream.h"
 
index 94194e0..bddf65e 100644 (file)
@@ -1,11 +1,12 @@
 #include <features.h>
+#ifdef __UCLIBC_HAVE_LFS__
 #define _FILE_OFFSET_BITS   64
 #define __USE_LARGEFILE64
 #define __USE_FILE_OFFSET64
+#include <dirent.h>
 #include <string.h>
 #include "dirstream.h"
 
-#ifdef __UCLIBC_HAVE_LFS__
 
 int alphasort64(const void * a, const void * b)
 {
index a2ac83b..3b6337b 100644 (file)
@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
index d6c1e66..b658b5a 100644 (file)
@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include "dirstream.h"
 
index 8131ffc..dc5c573 100644 (file)
@@ -24,12 +24,23 @@ Cambridge, MA 02139, USA.  */
 
 #define        _DIRSTREAM_H    1
 
+#include <features.h>
 #include <sys/types.h>
-#include <dirent.h>
 #ifdef _POSIX_THREADS
 #include <pthread.h>
 #endif
 
+
+#ifdef __UCLIBC_HAVE_LFS__
+#ifndef __USE_LARGEFILE64
+# define __USE_LARGEFILE64
+#endif
+# define stuff_t    __off64_t
+#else
+# define stuff_t    __off_t
+#endif
+
+
 /* For now, syscall readdir () only supports one entry at a time. It
  * will be changed in the future.
 #define NUMENT         3
@@ -48,19 +59,19 @@ struct __dirstream {
   int dd_fd;
 
   /* offset of the next dir entry in buffer */
-  off_t dd_nextloc;
+  stuff_t dd_nextloc;
 
   /* bytes of valid entries in buffer */
-  size_t dd_size;
+  stuff_t dd_size;
 
   /* -> directory buffer */
   void *dd_buf;
 
   /* offset of the next dir entry in directory. */
-  off_t dd_nextoff;
+  stuff_t dd_nextoff;
 
   /* total size of buffer */
-  size_t dd_max;
+  stuff_t dd_max;
  
   enum {unknown, have_getdents, no_getdents} dd_getdents;
 
index 25b5873..e2a6000 100644 (file)
@@ -37,19 +37,20 @@ DIR *opendir(const char *name)
                return NULL;
        }
 
+       ptr->dd_fd = fd;
+       ptr->dd_nextloc = ptr->dd_size = ptr->dd_nextoff = 0;
+       ptr->dd_getdents = unknown;
+
        ptr->dd_max = statbuf.st_blksize;
        if (ptr->dd_max < 512)
                ptr->dd_max = 512;
 
-       if (!(buf = malloc(ptr->dd_max))) {
+       if (!(buf = calloc(1, ptr->dd_max))) {
                close(fd);
                free(ptr);
                __set_errno(ENOMEM);
                return NULL;
        }
-       ptr->dd_fd = fd;
-       ptr->dd_nextoff = ptr->dd_nextloc = ptr->dd_size = 0;
        ptr->dd_buf = buf;
-       ptr->dd_getdents = unknown;
        return ptr;
 }
index d0f2803..c8f3b8d 100644 (file)
@@ -1,7 +1,9 @@
 #include <features.h>
+#ifdef __UCLIBC_HAVE_LFS__
 #define _FILE_OFFSET_BITS   64
 #define __USE_LARGEFILE64
 #define __USE_FILE_OFFSET64
+#include <dirent.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -9,8 +11,6 @@
 #include <dirent.h>
 #include "dirstream.h"
 
-#ifdef __UCLIBC_HAVE_LFS__
-
 extern int getdents64 __P ((unsigned int fd, struct dirent64 *dirp, unsigned int count));
 
 
@@ -33,7 +33,7 @@ struct dirent64 *readdir64(DIR * dir)
                /* read dir->dd_max bytes of directory entries. */
                result = getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
 
-               /* We assume we have getdents (). */
+               /* We assume we have getdents64 (). */
                dir->dd_getdents = have_getdents;
                if (result <= 0) {
                        result = -result;
@@ -63,6 +63,5 @@ struct dirent64 *readdir64(DIR * dir)
 
        return de;
 }
-#endif /* __UCLIBC_HAVE_LFS__ */
-
 
+#endif /* __UCLIBC_HAVE_LFS__ */
index 2fff910..4955940 100644 (file)
@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include "dirstream.h"
index 31ebce5..a460e16 100644 (file)
@@ -23,6 +23,7 @@
    SOFTWARE.
 */
 
+#include <dirent.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
index 6b08921..6c6697b 100644 (file)
 */
 
 #include <features.h>
+#ifdef __UCLIBC_HAVE_LFS__
 #define _FILE_OFFSET_BITS   64
 #define __USE_LARGEFILE64
 #define __USE_FILE_OFFSET64
+#include <dirent.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include "dirstream.h"
 
-#ifdef __UCLIBC_HAVE_LFS__
 
 /*
  * FIXME: This is a simple hack version which doesn't sort the data, and
index 3ff9f5d..a1649c9 100644 (file)
@@ -1,9 +1,10 @@
+#include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include "dirstream.h"
 
 
-void seekdir(DIR * dir, off_t offset)
+void seekdir(DIR * dir, long int offset)
 {
        if (!dir) {
                __set_errno(EBADF);
index 872cddb..8c13a9c 100644 (file)
@@ -1,9 +1,10 @@
+#include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include "dirstream.h"
 
 
-off_t telldir(DIR * dir)
+long int telldir(DIR * dir)
 {
        off_t offset;
 
index 01fbf54..7e3769a 100644 (file)
@@ -30,7 +30,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    //unsigned char d_type;
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -40,7 +42,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    //unsigned char d_type;
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index e299c77..82d8663 100644 (file)
@@ -30,7 +30,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    //unsigned char d_type;
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -40,7 +42,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    //unsigned char d_type;
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index bde9fa7..82d8663 100644 (file)
@@ -30,7 +30,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    /*unsigned char d_type; */
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -40,7 +42,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    /*unsigned char d_type; */
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index 88b7186..82d8663 100644 (file)
@@ -30,7 +30,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    /*unsigned char d_type;*/
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -40,7 +42,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    /*unsigned char d_type;*/
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index a2936a7..1d41f4d 100644 (file)
@@ -40,7 +40,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    //unsigned char d_type;
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -50,7 +52,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    //unsigned char d_type;
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index 1754c7c..472ae1a 100644 (file)
@@ -40,6 +40,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
index 88b7186..82d8663 100644 (file)
@@ -30,7 +30,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    /*unsigned char d_type;*/
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };
 
@@ -40,7 +42,7 @@ struct dirent64
     __ino64_t d_ino;
     __off64_t d_off;
     unsigned short int d_reclen;
-    /*unsigned char d_type;*/
+    unsigned char d_type;
     char d_name[256];          /* We must not include limits.h! */
   };
 #endif
index 1754c7c..472ae1a 100644 (file)
@@ -40,6 +40,9 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
+#ifdef __USE_FILE_OFFSET64
+    unsigned char d_type;
+#endif
     char d_name[256];          /* We must not include limits.h! */
   };