Browse Source

Scrub up some lingering problems preventing readdir64 from working
and creating several *64 problems, particualrly when client apps
used -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64. All better now.
-Erik

Eric Andersen 22 years ago
parent
commit
62653059d6

+ 1 - 0
libc/misc/dirent/alphasort.c

@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <string.h>
 #include "dirstream.h"
 

+ 2 - 1
libc/misc/dirent/alphasort64.c

@@ -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)
 {

+ 1 - 0
libc/misc/dirent/closedir.c

@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>

+ 1 - 0
libc/misc/dirent/dirfd.c

@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include "dirstream.h"
 

+ 16 - 5
libc/misc/dirent/dirstream.h

@@ -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;
 

+ 5 - 4
libc/misc/dirent/opendir.c

@@ -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;
 }

+ 4 - 5
libc/misc/dirent/readdir64.c

@@ -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__ */

+ 1 - 0
libc/misc/dirent/rewinddir.c

@@ -1,3 +1,4 @@
+#include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include "dirstream.h"

+ 1 - 0
libc/misc/dirent/scandir.c

@@ -23,6 +23,7 @@
    SOFTWARE.
 */
 
+#include <dirent.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>

+ 2 - 1
libc/misc/dirent/scandir64.c

@@ -24,16 +24,17 @@
 */
 
 #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

+ 2 - 1
libc/misc/dirent/seekdir.c

@@ -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);

+ 2 - 1
libc/misc/dirent/telldir.c

@@ -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;
 

+ 4 - 2
libc/sysdeps/linux/arm/bits/dirent.h

@@ -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

+ 4 - 2
libc/sysdeps/linux/i386/bits/dirent.h

@@ -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

+ 4 - 2
libc/sysdeps/linux/m68k/bits/dirent.h

@@ -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

+ 4 - 2
libc/sysdeps/linux/mips/bits/dirent.h

@@ -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

+ 4 - 2
libc/sysdeps/linux/powerpc/bits/dirent.h

@@ -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

+ 3 - 0
libc/sysdeps/linux/sh/bits/dirent.h

@@ -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! */
   };
 

+ 4 - 2
libc/sysdeps/linux/sparc/bits/dirent.h

@@ -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

+ 3 - 0
libc/sysdeps/linux/v850/bits/dirent.h

@@ -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! */
   };