+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.
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
-/* 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
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);
}
--- /dev/null
+/* 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);
+}
#endif
#ifdef __USE_LARGEFILE64
+extern struct dirent64 *__readdir64 __P ((DIR *__dirp));
extern struct dirent64 *readdir64 __P ((DIR *__dirp));
#endif
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.
while ((d = __readdir (dp)) != NULL)
if (select == NULL || (*select) (d))
{
+ struct dirent *vnew;
size_t dsize;
/* Ignore errors from select or readdir */
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)
--- /dev/null
+/* 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;
+}
-/* 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
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);
}
--- /dev/null
+/* 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);
+}
-/* 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
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
-/* 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>
-/* 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
/* Read a directory entry from DIRP. */
struct dirent64 *
-readdir64 (DIR *dirp)
+__readdir64 (DIR *dirp)
{
struct dirent64 *dp;
return dp;
}
+weak_alias (__readdir64, readdir64)