about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-03-20 12:06:55 +0000
committerUlrich Drepper <drepper@redhat.com>1998-03-20 12:06:55 +0000
commit89a9e37b7a7a2134cedb6d27db265a8ab774f9d1 (patch)
tree19131b4a9aa63f7737c683a57a00b1b37bf7b701
parent9c1a1da9866c22c1626f2222cf5d03ef1b0ede3b (diff)
downloadglibc-89a9e37b7a7a2134cedb6d27db265a8ab774f9d1.tar.gz
glibc-89a9e37b7a7a2134cedb6d27db265a8ab774f9d1.tar.xz
glibc-89a9e37b7a7a2134cedb6d27db265a8ab774f9d1.zip
Update.
1998-03-20 11:58  Ulrich Drepper  <drepper@cygnus.com>

	* dirent/Makefile (routines): Add scandir64, alphasort64, and
	versionsort64.
	* dirent/alphasort64.c: New file.
	* dirent/scandir64.c: New file.
	* dirent/versionsort64.c: New file.
	* dirent/dirent.h: Add LFS support for scandir, alphasort, and
	versionsort.
	* sysdeps/generic/readdir64.c: Rename to __readdir64 and make
	old name weak alias.
	* sysdeps/unix/sysv/linux/readdir64.c: Likewise.

	* dirent/alphasort.c: Use strcoll instead of strcmp.

	* dirent/scandir.c: Optimize a bit.

	* dirent/versionsort.c: Pretty print.

1998-03-20  Ulrich Drepper  <drepper@cygnus.com>

	* string/string.h: Add prototype for __strtok_r.
-rw-r--r--ChangeLog23
-rw-r--r--dirent/Makefile3
-rw-r--r--dirent/alphasort.c6
-rw-r--r--dirent/alphasort64.c27
-rw-r--r--dirent/dirent.h46
-rw-r--r--dirent/scandir.c15
-rw-r--r--dirent/scandir64.c93
-rw-r--r--dirent/versionsort.c4
-rw-r--r--dirent/versionsort64.c27
-rw-r--r--string/string.h6
-rw-r--r--sysdeps/generic/readdir64.c5
-rw-r--r--sysdeps/unix/sysv/linux/readdir64.c5
12 files changed, 232 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e4c63a304..da8df72b7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+1998-03-20 11:58  Ulrich Drepper  <drepper@cygnus.com>
+
+	* dirent/Makefile (routines): Add scandir64, alphasort64, and
+	versionsort64.
+	* dirent/alphasort64.c: New file.
+	* dirent/scandir64.c: New file.
+	* dirent/versionsort64.c: New file.
+	* dirent/dirent.h: Add LFS support for scandir, alphasort, and
+	versionsort.
+	* sysdeps/generic/readdir64.c: Rename to __readdir64 and make
+	old name weak alias.
+	* sysdeps/unix/sysv/linux/readdir64.c: Likewise.
+
+	* dirent/alphasort.c: Use strcoll instead of strcmp.
+
+	* dirent/scandir.c: Optimize a bit.
+
+	* dirent/versionsort.c: Pretty print.
+
+1998-03-20  Ulrich Drepper  <drepper@cygnus.com>
+
+	* string/string.h: Add prototype for __strtok_r.
+
 1998-03-20 12:14  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
 
 	* posix/Makefile: Fix typo in last change.
diff --git a/dirent/Makefile b/dirent/Makefile
index e763dabeb7..aebbd64b5f 100644
--- a/dirent/Makefile
+++ b/dirent/Makefile
@@ -24,7 +24,8 @@ subdir		:= dirent
 headers		:= dirent.h bits/dirent.h
 routines	:= opendir closedir readdir readdir_r rewinddir \
 		   seekdir telldir scandir alphasort versionsort \
-		   getdents dirfd readdir64 readdir64_r
+		   getdents dirfd readdir64 readdir64_r scandir64 \
+		   alphasort64 versionsort64
 distribute := dirstream.h
 
 tests	   := list tst-seekdir opendir-tst1
diff --git a/dirent/alphasort.c b/dirent/alphasort.c
index 95e0da056c..a589775ef1 100644
--- a/dirent/alphasort.c
+++ b/dirent/alphasort.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1997, 1998 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
@@ -22,6 +22,6 @@
 int
 alphasort (const void *a, const void *b)
 {
-  return strcmp ((*(const struct dirent **) a)->d_name,
-		 (*(const struct dirent **) b)->d_name);
+  return strcoll ((*(const struct dirent **) a)->d_name,
+		  (*(const struct dirent **) b)->d_name);
 }
diff --git a/dirent/alphasort64.c b/dirent/alphasort64.c
new file mode 100644
index 0000000000..d48004f2c4
--- /dev/null
+++ b/dirent/alphasort64.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1992, 1997, 1998 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 <string.h>
+
+int
+alphasort64 (const void *a, const void *b)
+{
+  return strcoll ((*(const struct dirent64 **) a)->d_name,
+		  (*(const struct dirent64 **) b)->d_name);
+}
diff --git a/dirent/dirent.h b/dirent/dirent.h
index 63986bfc0f..07d543b6e2 100644
--- a/dirent/dirent.h
+++ b/dirent/dirent.h
@@ -135,6 +135,7 @@ extern struct dirent *readdir __P ((DIR *__dirp)) __asm__ ("readdir64");
 #endif
 
 #ifdef __USE_LARGEFILE64
+extern struct dirent64 *__readdir64 __P ((DIR *__dirp));
 extern struct dirent64 *readdir64 __P ((DIR *__dirp));
 #endif
 
@@ -199,18 +200,49 @@ extern int dirfd __P ((DIR *__dirp));
    Entries for which SELECT returns nonzero are individually malloc'd,
    sorted using qsort with CMP, and collected in a malloc'd array in
    *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
-extern int scandir __P ((__const char *__dir,
-			 struct dirent ***__namelist,
-			 int (*__selector) __P ((__const struct dirent *)),
-			 int (*__cmp) __P ((__const __ptr_t,
-					    __const __ptr_t))));
+# ifndef __USE_FILE_OFFSET64
+extern int scandir __P ((__const char *__dir, struct dirent ***__namelist,
+			 int (*__selector) (__const struct dirent *),
+			 int (*__cmp) (__const __ptr_t, __const __ptr_t)));
+# else
+extern int scandir __P ((__const char *__dir, struct dirent ***__namelist,
+			 int (*__selector) (__const struct dirent *),
+			 int (*__cmp) (__const __ptr_t, __const __ptr_t)))
+     __asm__ ("scandir64");
+# endif
+
+# if defined __USE_GNU && defined __USE_LARGEFILE64
+/* This function is like `scandir' but it uses the 64bit dirent structure.
+   Please note that the CMP function must now work with struct dirent64 **.  */
+extern int scandir64 __P ((__const char *__dir, struct dirent64 ***__namelist,
+			 int (*__selector) (__const struct dirent64 *),
+			 int (*__cmp) (__const __ptr_t, __const __ptr_t)));
+# endif
 
 /* Function to compare two `struct dirent's alphabetically.  */
-extern int alphasort __P ((__const __ptr_t, __const __ptr_t));
+# ifndef __USE_FILE_OFFSET64
+extern int alphasort __P ((__const __ptr_t __e1, __const __ptr_t __e2));
+# else
+extern int alphasort __P ((__const __ptr_t __e1, __const __ptr_t __e2))
+     __asm__ ("alphasort64");
+# endif
+
+# if defined __USE_GNU && defined __USE_LARGEFILE64
+extern int alphasort64 __P ((__const __ptr_t __e1, __const __ptr_t __e2));
+# endif
 
 # ifdef __USE_GNU
 /* Function to compare two `struct dirent's by name & version.  */
-extern int versionsort __P ((__const __ptr_t, __const __ptr_t));
+#  ifndef __USE_FILE_OFFSET64
+extern int versionsort __P ((__const __ptr_t __e1, __const __ptr_t __e2));
+#  else
+extern int versionsort __P ((__const __ptr_t __e1, __const __ptr_t __e2))
+     __asm__ ("versionsort64");
+#  endif
+
+#  ifdef __USE_LARGEFILE64
+extern int versionsort64 __P ((__const __ptr_t __e1, __const __ptr_t __e2));
+#  endif
 # endif
 
 /* Read directory entries from FD into BUF, reading at most NBYTES.
diff --git a/dirent/scandir.c b/dirent/scandir.c
index ef7531fa95..cffc8a98cb 100644
--- a/dirent/scandir.c
+++ b/dirent/scandir.c
@@ -44,6 +44,7 @@ scandir (dir, namelist, select, cmp)
   while ((d = __readdir (dp)) != NULL)
     if (select == NULL || (*select) (d))
       {
+	struct dirent *vnew;
 	size_t dsize;
 
 	/* Ignore errors from select or readdir */
@@ -58,20 +59,16 @@ scandir (dir, namelist, select, cmp)
 	      vsize *= 2;
 	    new = (struct dirent **) realloc (v, vsize * sizeof (*v));
 	    if (new == NULL)
-	      {
-	      lose:
-		__set_errno (ENOMEM);
-		break;
-	      }
+	      break;
 	    v = new;
 	  }
 
 	dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
-	v[i] = (struct dirent *) malloc (dsize);
-	if (v[i] == NULL)
-	  goto lose;
+	vnew = (struct dirent *) malloc (dsize);
+	if (vnew == NULL)
+	  break;
 
-	memcpy (v[i++], d, dsize);
+	v[i++] = (struct dirent *) memcpy (vnew, d, dsize);
       }
 
   if (errno != 0)
diff --git a/dirent/scandir64.c b/dirent/scandir64.c
new file mode 100644
index 0000000000..a0b7406aac
--- /dev/null
+++ b/dirent/scandir64.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1992, 93, 94, 95, 96, 97, 98 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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int
+scandir64 (dir, namelist, select, cmp)
+     const char *dir;
+     struct dirent64 ***namelist;
+     int (*select) __P ((const struct dirent64 *));
+     int (*cmp) __P ((const void *, const void *));
+{
+  DIR *dp = opendir (dir);
+  struct dirent64 **v = NULL;
+  size_t vsize = 0, i;
+  struct dirent64 *d;
+  int save;
+
+  if (dp == NULL)
+    return -1;
+
+  save = errno;
+  __set_errno (0);
+
+  i = 0;
+  while ((d = __readdir64 (dp)) != NULL)
+    if (select == NULL || (*select) (d))
+      {
+	struct dirent64 *vnew;
+	size_t dsize;
+
+	/* Ignore errors from select or readdir */
+	__set_errno (0);
+
+	if (i == vsize)
+	  {
+	    struct dirent64 **new;
+	    if (vsize == 0)
+	      vsize = 10;
+	    else
+	      vsize *= 2;
+	    new = (struct dirent64 **) realloc (v, vsize * sizeof (*v));
+	    if (new == NULL)
+	      break;
+	    v = new;
+	  }
+
+	dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
+	vnew = (struct dirent64 *) malloc (dsize);
+	if (vnew == NULL)
+	  break;
+
+	v[i++] = (struct dirent64 *) memcpy (vnew, d, dsize);
+      }
+
+  if (errno != 0)
+    {
+      save = errno;
+      (void) closedir (dp);
+      while (i > 0)
+	free (v[--i]);
+      free (v);
+      __set_errno (save);
+      return -1;
+    }
+
+  (void) closedir (dp);
+  __set_errno (save);
+
+  /* Sort the list if we have a comparison function to sort with.  */
+  if (cmp != NULL)
+    qsort (v, i, sizeof (*v), cmp);
+  *namelist = v;
+  return i;
+}
diff --git a/dirent/versionsort.c b/dirent/versionsort.c
index 182680bc45..88d6a614e5 100644
--- a/dirent/versionsort.c
+++ b/dirent/versionsort.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1997, 1998 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
@@ -23,5 +23,5 @@ int
 versionsort (const void *a, const void *b)
 {
   return strverscmp ((*(const struct dirent **) a)->d_name,
-		 (*(const struct dirent **) b)->d_name);
+		     (*(const struct dirent **) b)->d_name);
 }
diff --git a/dirent/versionsort64.c b/dirent/versionsort64.c
new file mode 100644
index 0000000000..b21f246e83
--- /dev/null
+++ b/dirent/versionsort64.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1992, 1997, 1998 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 <string.h>
+
+int
+versionsort64 (const void *a, const void *b)
+{
+  return strverscmp ((*(const struct dirent64 **) a)->d_name,
+		     (*(const struct dirent64 **) b)->d_name);
+}
diff --git a/string/string.h b/string/string.h
index 51144696ca..b8c33b00b1 100644
--- a/string/string.h
+++ b/string/string.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 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
@@ -167,9 +167,11 @@ extern char *strcasestr __P ((__const char *__haystack,
 extern char *strtok __P ((char *__restrict __s,
 			  __const char *__restrict __delim));
 
-#if defined __USE_POSIX || defined __USE_MISC
 /* Divide S into tokens separated by characters in DELIM.  Information
    passed between calls are stored in SAVE_PTR.  */
+extern char *__strtok_r __P ((char *__s, __const char *__delim,
+			      char **__save_ptr));
+#if defined __USE_POSIX || defined __USE_MISC
 extern char *strtok_r __P ((char *__s, __const char *__delim,
 			    char **__save_ptr));
 #endif
diff --git a/sysdeps/generic/readdir64.c b/sysdeps/generic/readdir64.c
index ce84340c8e..db26b9b1f6 100644
--- a/sysdeps/generic/readdir64.c
+++ b/sysdeps/generic/readdir64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1995, 1996, 1997, 1998 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
@@ -22,10 +22,11 @@
 
 /* Read a directory entry from DIRP.  */
 struct dirent64 *
-readdir64 (DIR *dirp)
+__readdir64 (DIR *dirp)
 {
   __set_errno (ENOSYS);
   return NULL;
 }
+weak_alias (__readdir64, readdir64)
 stub_warning (readdir64)
 #include <stub-tag.h>
diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c
index 37623655f4..710f934ebb 100644
--- a/sysdeps/unix/sysv/linux/readdir64.c
+++ b/sysdeps/unix/sysv/linux/readdir64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998 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
@@ -32,7 +32,7 @@ extern ssize_t __getdirentries64 (int, char *, size_t, off_t *);
 
 /* Read a directory entry from DIRP.  */
 struct dirent64 *
-readdir64 (DIR *dirp)
+__readdir64 (DIR *dirp)
 {
   struct dirent64 *dp;
 
@@ -101,3 +101,4 @@ readdir64 (DIR *dirp)
 
   return dp;
 }
+weak_alias (__readdir64, readdir64)