aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-04-27 13:06:39 +0000
committerUlrich Drepper <drepper@redhat.com>1999-04-27 13:06:39 +0000
commit980e58323af243dd0a87f6a6eeec6f97308b46e5 (patch)
tree553907bc56fa9387a688da4efb5e9d710abefb22
parentb6a7609d56147398e6fa412fd7c7210960300505 (diff)
downloadglibc-980e58323af243dd0a87f6a6eeec6f97308b46e5.tar
glibc-980e58323af243dd0a87f6a6eeec6f97308b46e5.tar.gz
glibc-980e58323af243dd0a87f6a6eeec6f97308b46e5.tar.bz2
glibc-980e58323af243dd0a87f6a6eeec6f97308b46e5.zip
Update.
* include/dirent.h: Remove __getdirentries declaration, add __getdents and __getdents64. * sysdeps/unix/readdir.c: Use __getdents, not __getdirentries. * sysdeps/unix/readdir_r.c: Likewise. * sysdeps/unix/sysv/linux/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/getdents.c: Define __getdents, not __getdirentries. Remove fourth argument. * sysdeps/unix/sysv/linux/getdirentries.c: New file. * sysdeps/unix/sysv/linux/getdirentries64.c: New file. * sysdeps/unix/sysv/linux/Makefile [subdir=dirent] (sysdep_routines): Add getdirentries and getdirentries64. * sysdeps/unix/sysv/linux/Dist: Add getdirentries and getdirentries64.
-rw-r--r--ChangeLog14
-rw-r--r--include/dirent.h6
-rw-r--r--sysdeps/unix/readdir.c6
-rw-r--r--sysdeps/unix/readdir_r.c6
-rw-r--r--sysdeps/unix/sysv/linux/Dist2
-rw-r--r--sysdeps/unix/sysv/linux/Makefile2
-rw-r--r--sysdeps/unix/sysv/linux/getdents.c37
-rw-r--r--sysdeps/unix/sysv/linux/getdirentries.c39
-rw-r--r--sysdeps/unix/sysv/linux/getdirentries64.c2
-rw-r--r--sysdeps/unix/sysv/linux/readdir64.c9
-rw-r--r--sysdeps/unix/sysv/linux/readdir64_r.c9
11 files changed, 88 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c06e3e820..38a0b6dfc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
1999-04-27 Ulrich Drepper <drepper@cygnus.com>
+ * include/dirent.h: Remove __getdirentries declaration, add __getdents
+ and __getdents64.
+ * sysdeps/unix/readdir.c: Use __getdents, not __getdirentries.
+ * sysdeps/unix/readdir_r.c: Likewise.
+ * sysdeps/unix/sysv/linux/readdir64.c: Likewise.
+ * sysdeps/unix/sysv/linux/readdir64_r.c: Likewise.
+ * sysdeps/unix/sysv/linux/getdents.c: Define __getdents, not
+ __getdirentries. Remove fourth argument.
+ * sysdeps/unix/sysv/linux/getdirentries.c: New file.
+ * sysdeps/unix/sysv/linux/getdirentries64.c: New file.
+ * sysdeps/unix/sysv/linux/Makefile [subdir=dirent] (sysdep_routines):
+ Add getdirentries and getdirentries64.
+ * sysdeps/unix/sysv/linux/Dist: Add getdirentries and getdirentries64.
+
* posix/fnmatch.c (internal_fnmatch): Correctly reset string
pointer in case of an invalid [[: expression.
diff --git a/include/dirent.h b/include/dirent.h
index 58d7546c4a..f6a3ed8741 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -8,6 +8,8 @@ extern struct dirent *__readdir __P ((DIR *__dirp));
extern struct dirent64 *__readdir64 __P ((DIR *__dirp));
extern int __readdir_r __P ((DIR *__dirp, struct dirent *__entry,
struct dirent **__result));
-extern __ssize_t __getdirentries __P ((int __fd, char *__buf,
- size_t __nbytes, __off_t *__basep));
+extern __ssize_t __getdents __P ((int __fd, char *__buf, size_t __nbytes))
+ internal_function;
+extern __ssize_t __getdents64 __P ((int __fd, char *__buf, size_t __nbytes))
+ internal_function;
#endif
diff --git a/sysdeps/unix/readdir.c b/sysdeps/unix/readdir.c
index fd26b707a9..a17a26435d 100644
--- a/sysdeps/unix/readdir.c
+++ b/sysdeps/unix/readdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -45,7 +45,6 @@ __readdir (DIR *dirp)
/* We've emptied out our buffer. Refill it. */
size_t maxread;
- off_t base;
ssize_t bytes;
#ifndef _DIRENT_HAVE_D_RECLEN
@@ -55,8 +54,7 @@ __readdir (DIR *dirp)
maxread = dirp->allocation;
#endif
- base = dirp->filepos;
- bytes = __getdirentries (dirp->fd, dirp->data, maxread, &base);
+ bytes = __getdents (dirp->fd, dirp->data, maxread);
if (bytes <= 0)
{
dp = NULL;
diff --git a/sysdeps/unix/readdir_r.c b/sysdeps/unix/readdir_r.c
index 15a4c3775c..8d5cfdca16 100644
--- a/sysdeps/unix/readdir_r.c
+++ b/sysdeps/unix/readdir_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -44,7 +44,6 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
/* We've emptied out our buffer. Refill it. */
size_t maxread;
- off_t base;
ssize_t bytes;
#ifndef _DIRENT_HAVE_D_RECLEN
@@ -54,8 +53,7 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
maxread = dirp->allocation;
#endif
- base = dirp->filepos;
- bytes = __getdirentries (dirp->fd, dirp->data, maxread, &base);
+ bytes = __getdents (dirp->fd, dirp->data, maxread);
if (bytes <= 0)
{
dp = NULL;
diff --git a/sysdeps/unix/sysv/linux/Dist b/sysdeps/unix/sysv/linux/Dist
index 6039e9ae0a..fca513d1b7 100644
--- a/sysdeps/unix/sysv/linux/Dist
+++ b/sysdeps/unix/sysv/linux/Dist
@@ -1,6 +1,8 @@
bits/pthreadtypes.h
cmsg_nxthdr.c
errlist.h
+getdirentries.c
+getdirentries64.c
init-first.h
kernel_sigaction.h
kernel_stat.h
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 0a8f45448b..69c08ea902 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -97,7 +97,7 @@ endif
inhibit-glue = yes
ifeq ($(subdir),dirent)
-sysdep_routines += getdents64
+sysdep_routines += getdents64 getdirentries getdirentries64
endif
ifeq ($(subdir),nis)
diff --git a/sysdeps/unix/sysv/linux/getdents.c b/sysdeps/unix/sysv/linux/getdents.c
index e0180dfa2e..9a2255c0da 100644
--- a/sysdeps/unix/sysv/linux/getdents.c
+++ b/sysdeps/unix/sysv/linux/getdents.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -51,22 +51,23 @@ struct kernel_dirent
};
#ifdef GETDENTS64
-#define __getdirentries __getdirentries64
-#define dirent dirent64
+# define __getdents __getdents64
+# define dirent dirent64
#endif
/* The problem here is that we cannot simply read the next NBYTES
bytes. We need to take the additional field into account. We use
some heuristic. Assuming the directory contains names with 14
- characters on average we can compute an estimate number of entries
+ characters on average we can compute an estimated number of entries
which fit in the buffer. Taking this number allows us to specify a
- correct number of bytes to read. If we should be wrong, we can reset
- the file descriptor. */
+ reasonable number of bytes to read. If we should be wrong, we can
+ reset the file descriptor. In practice the kernel is limiting the
+ amount of data returned much more then the reduced buffer size. */
ssize_t
-__getdirentries (int fd, char *buf, size_t nbytes, off_t *basep)
+internal_function
+__getdents (int fd, char *buf, size_t nbytes)
{
- off_t base = __lseek (fd, (off_t) 0, SEEK_CUR);
- off_t last_offset = base;
+ off_t last_offset = 0;
size_t red_nbytes;
struct kernel_dirent *skdp, *kdp;
struct dirent *dp;
@@ -84,7 +85,7 @@ __getdirentries (int fd, char *buf, size_t nbytes, off_t *basep)
if (retval == -1)
return -1;
-
+
while ((char *) kdp < (char *) skdp + retval)
{
const size_t alignment = __alignof__ (struct dirent);
@@ -95,8 +96,13 @@ __getdirentries (int fd, char *buf, size_t nbytes, off_t *basep)
if ((char *) dp + new_reclen > buf + nbytes)
{
/* Our heuristic failed. We read too many entries. Reset
- the stream. */
- __lseek (fd, last_offset, SEEK_SET);
+ the stream. `last_offset' contains the last known
+ position. If it is zero this is the first record we are
+ reading. In this case do a relative search. */
+ if (last_offset == 0)
+ __lseek (fd, -retval, SEEK_CUR);
+ else
+ __lseek (fd, last_offset, SEEK_SET);
break;
}
@@ -112,12 +118,5 @@ __getdirentries (int fd, char *buf, size_t nbytes, off_t *basep)
kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen);
}
- if (basep)
- *basep = base;
-
return (char *) dp - buf;
}
-
-#ifndef GETDENTS64
-weak_alias (__getdirentries, getdirentries)
-#endif
diff --git a/sysdeps/unix/sysv/linux/getdirentries.c b/sysdeps/unix/sysv/linux/getdirentries.c
new file mode 100644
index 0000000000..1f7ba85c55
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getdirentries.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <dirent.h>
+#include <unistd.h>
+
+#ifdef GETDENTS64
+# define getdirentries getdirentries64
+# define __getdents __getdents64
+#endif
+
+ssize_t
+getdirentries (int fd, char *buf, size_t nbytes, off_t *basep)
+{
+ off_t base = __lseek (fd, (off_t) 0, SEEK_CUR);
+ ssize_t result;
+
+ result = __getdents (fd, buf, nbytes);
+
+ if (result != -1)
+ *basep = base;
+
+ return result;
+}
diff --git a/sysdeps/unix/sysv/linux/getdirentries64.c b/sysdeps/unix/sysv/linux/getdirentries64.c
new file mode 100644
index 0000000000..423e361e22
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getdirentries64.c
@@ -0,0 +1,2 @@
+#define GETDENTS64 1
+#include "getdirentries.c"
diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c
index 710f934ebb..5a19e220aa 100644
--- a/sysdeps/unix/sysv/linux/readdir64.c
+++ b/sysdeps/unix/sysv/linux/readdir64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -27,9 +27,6 @@
#include <dirstream.h>
-extern ssize_t __getdirentries64 (int, char *, size_t, off_t *);
-
-
/* Read a directory entry from DIRP. */
struct dirent64 *
__readdir64 (DIR *dirp)
@@ -47,7 +44,6 @@ __readdir64 (DIR *dirp)
/* We've emptied out our buffer. Refill it. */
size_t maxread;
- off_t base;
ssize_t bytes;
#ifndef _DIRENT_HAVE_D_RECLEN
@@ -57,8 +53,7 @@ __readdir64 (DIR *dirp)
maxread = dirp->allocation;
#endif
- base = dirp->filepos;
- bytes = __getdirentries64 (dirp->fd, dirp->data, maxread, &base);
+ bytes = __getdents64 (dirp->fd, dirp->data, maxread);
if (bytes <= 0)
{
dp = NULL;
diff --git a/sysdeps/unix/sysv/linux/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir64_r.c
index 5e711c4787..a86ef7b8d2 100644
--- a/sysdeps/unix/sysv/linux/readdir64_r.c
+++ b/sysdeps/unix/sysv/linux/readdir64_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -27,9 +27,6 @@
#include <dirstream.h>
-extern ssize_t __getdirentries64 (int, char *, size_t, off_t *);
-
-
/* Read a directory entry from DIRP, store result in ENTRY and return
pointer to result in *RESULT. */
int
@@ -47,7 +44,6 @@ readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
/* We've emptied out our buffer. Refill it. */
size_t maxread;
- off_t base;
ssize_t bytes;
#ifndef _DIRENT_HAVE_D_RECLEN
@@ -57,8 +53,7 @@ readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
maxread = dirp->allocation;
#endif
- base = dirp->filepos;
- bytes = __getdirentries64 (dirp->fd, dirp->data, maxread, &base);
+ bytes = __getdents64 (dirp->fd, dirp->data, maxread);
if (bytes <= 0)
{
dp = NULL;