Update.
authorUlrich Drepper <drepper@redhat.com>
Fri, 20 Mar 1998 12:06:55 +0000 (12:06 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 20 Mar 1998 12:06:55 +0000 (12:06 +0000)
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.

12 files changed:
ChangeLog
dirent/Makefile
dirent/alphasort.c
dirent/alphasort64.c [new file with mode: 0644]
dirent/dirent.h
dirent/scandir.c
dirent/scandir64.c [new file with mode: 0644]
dirent/versionsort.c
dirent/versionsort64.c [new file with mode: 0644]
string/string.h
sysdeps/generic/readdir64.c
sysdeps/unix/sysv/linux/readdir64.c

index 5e4c63a..da8df72 100644 (file)
--- 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.
index e763dab..aebbd64 100644 (file)
@@ -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
index 95e0da0..a589775 100644 (file)
@@ -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 (file)
index 0000000..d48004f
--- /dev/null
@@ -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);
+}
index 63986bf..07d543b 100644 (file)
@@ -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.
index ef7531f..cffc8a9 100644 (file)
@@ -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 (file)
index 0000000..a0b7406
--- /dev/null
@@ -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;
+}
index 182680b..88d6a61 100644 (file)
@@ -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 (file)
index 0000000..b21f246
--- /dev/null
@@ -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);
+}
index 5114469..b8c33b0 100644 (file)
@@ -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
index ce84340..db26b9b 100644 (file)
@@ -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
 
 /* 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>
index 3762365..710f934 100644 (file)
@@ -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)