summary refs log tree commit diff
path: root/dirent
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 /dirent
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.
Diffstat (limited to 'dirent')
-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
8 files changed, 199 insertions, 22 deletions
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);
+}