Kaynağa Gözat

Remove simulated d_type support for getdents and the dirent struct, and use
the straight getdents syscall instead of the wrapper (which leaked memory).

Manuel Novoa III 23 yıl önce
ebeveyn
işleme
96b91643c3

+ 1 - 11
libc/misc/dirent/readdir.c

@@ -55,15 +55,5 @@ struct dirent *readdir(DIR * dir)
 	/* We have to save the next offset here. */
 	dir->dd_nextoff = de->d_off;
 
-	/* convert */
-	dir->dd_buf->d_ino = de->d_ino;
-	dir->dd_buf->d_off = de->d_off;
-	dir->dd_buf->d_reclen = de->d_reclen;
-	dir->dd_buf->d_type = 0;
-	if (strlen((char *) &de->d_type) > 10)
-		de->d_name[10] = 0;
-	strcpy(dir->dd_buf->d_name, (char *) &de->d_name);
-	__set_errno(0);
-
-	return dir->dd_buf;
+	return de;
 }

+ 2 - 2
libc/sysdeps/linux/common/Makefile

@@ -24,9 +24,9 @@
 TOPDIR=../../../../
 include $(TOPDIR)Rules.mak
 
-CSRC=	waitpid.c getdents.c kernel_version.c statfix.c getdnnm.c tell.c gethstnm.c \
+CSRC=	waitpid.c kernel_version.c statfix.c getdnnm.c tell.c gethstnm.c \
 	mkfifo.c setegid.c wait.c errno.c getpagesize.c  seteuid.c wait3.c setpgrp.c \
-	getdtablesize.c create_module.c ptrace.c
+	getdtablesize.c create_module.c ptrace.c # getdents.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 
 MSRC=syscalls.c

+ 1 - 1
libc/sysdeps/linux/common/str_syscalls.sh

@@ -29,6 +29,6 @@ echo "printf(\"#define __STR_NR_fcntl    __STR_NR__fcntl\n\");"
 echo "printf(\"#define __STR_NR_reboot   __STR_NR__reboot\n\");"
 echo "printf(\"#define __STR_NR_mmap     __STR_NR__mmap\n\");"
 echo "printf(\"#define __STR_NR_syslog   __STR_NR__syslog\n\");"
-echo "printf(\"#define __STR_NR_getdents __STR_NR__getdents\n\");"
+#echo "printf(\"#define __STR_NR_getdents __STR_NR__getdents\n\");"
 echo
 echo "return EXIT_SUCCESS; }"

+ 2 - 3
libc/sysdeps/linux/common/syscalls.c

@@ -984,11 +984,10 @@ loff_t llseek(int fd, loff_t offset, int whence)
 #endif
 
 //#define __NR_getdents         141
-#ifdef L__getdents
-#define __NR__getdents __NR_getdents
+#ifdef L_getdents
 #include <unistd.h>
 #include <dirent.h>
-_syscall3(int, _getdents, int, fd, char *, dirp, size_t, count);
+_syscall3(int, getdents, int, fd, char *, dirp, size_t, count);
 #endif
 
 //#define __NR__newselect       142

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

@@ -16,6 +16,16 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+/*
+ * June 25, 2001
+ *
+ * Removed d_type support for dirent and undefined _DIRENT_HAVE_D_TYPE;
+ * i.e. match the kernel structs and avoid any translation for now.
+ * Note: glibc fakes d_type for the dirent case.
+ * Note: dirent64 still has the d_type field.
+ */
+
+
 #ifndef _DIRENT_H
 # error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
 #endif
@@ -30,7 +40,6 @@ struct dirent
     __off64_t d_off;
 #endif
     unsigned short int d_reclen;
-    unsigned char d_type;
     char d_name[256];		/* We must not include limits.h! */
   };
 
@@ -50,4 +59,4 @@ struct dirent64
 #undef  _DIRENT_HAVE_D_NAMLEN
 #define _DIRENT_HAVE_D_RECLEN
 #define _DIRENT_HAVE_D_OFF
-#define _DIRENT_HAVE_D_TYPE
+#undef  _DIRENT_HAVE_D_TYPE