X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fscandir.c;h=e17788c1d123b2bc5b4cad553ef59bf31825c063;hb=387c96fc38b1985d677a25881ab99a449a00af22;hp=54a74d5e047e058a9322ca99132b8508dd297db5;hpb=fc333501ca97880108c8ff17e33d9dd7d5e28ed4;p=gnulib.git
diff --git a/lib/scandir.c b/lib/scandir.c
index 54a74d5e0..e17788c1d 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1992-1998, 2000, 2002, 2003, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1992-1998, 2000, 2002-2003, 2009-2012 Free Software
+ Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify it
@@ -12,8 +13,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see . */
#include
@@ -32,6 +32,13 @@
#undef select
+#ifndef _D_EXACT_NAMLEN
+# define _D_EXACT_NAMLEN(d) strlen ((d)->d_name)
+#endif
+#ifndef _D_ALLOC_NAMLEN
+# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
+#endif
+
#if _LIBC
# ifndef SCANDIR
# define SCANDIR scandir
@@ -83,9 +90,9 @@ cancel_handler (void *arg)
int
SCANDIR (const char *dir,
- DIRENT_TYPE ***namelist,
- int (*select) (const DIRENT_TYPE *),
- int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **))
+ DIRENT_TYPE ***namelist,
+ int (*select) (const DIRENT_TYPE *),
+ int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **))
{
DIR *dp = __opendir (dir);
DIRENT_TYPE **v = NULL;
@@ -112,43 +119,43 @@ SCANDIR (const char *dir,
int use_it = select == NULL;
if (! use_it)
- {
- use_it = select (d);
- /* The select function might have changed errno. It was
- zero before and it need to be again to make the latter
- tests work. */
- __set_errno (0);
- }
+ {
+ use_it = select (d);
+ /* The select function might have changed errno. It was
+ zero before and it need to be again to make the latter
+ tests work. */
+ __set_errno (0);
+ }
if (use_it)
- {
- DIRENT_TYPE *vnew;
- size_t dsize;
-
- /* Ignore errors from select or readdir */
- __set_errno (0);
-
- if (__builtin_expect (c.cnt == vsize, 0))
- {
- DIRENT_TYPE **new;
- if (vsize == 0)
- vsize = 10;
- else
- vsize *= 2;
- new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v));
- if (new == NULL)
- break;
- v = new;
- c.v = (void *) v;
- }
-
- dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
- vnew = (DIRENT_TYPE *) malloc (dsize);
- if (vnew == NULL)
- break;
-
- v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize);
- }
+ {
+ DIRENT_TYPE *vnew;
+ size_t dsize;
+
+ /* Ignore errors from select or readdir */
+ __set_errno (0);
+
+ if (__builtin_expect (c.cnt == vsize, 0))
+ {
+ DIRENT_TYPE **new;
+ if (vsize == 0)
+ vsize = 10;
+ else
+ vsize *= 2;
+ new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v));
+ if (new == NULL)
+ break;
+ v = new;
+ c.v = (void *) v;
+ }
+
+ dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
+ vnew = (DIRENT_TYPE *) malloc (dsize);
+ if (vnew == NULL)
+ break;
+
+ v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize);
+ }
}
if (__builtin_expect (errno, 0) != 0)
@@ -156,7 +163,7 @@ SCANDIR (const char *dir,
save = errno;
while (c.cnt > 0)
- free (v[--c.cnt]);
+ free (v[--c.cnt]);
free (v);
c.cnt = -1;
}
@@ -164,7 +171,7 @@ SCANDIR (const char *dir,
{
/* Sort the list if we have a comparison function to sort with. */
if (cmp != NULL)
- qsort (v, c.cnt, sizeof (*v), (int (*) (const void *, const void *)) cmp);
+ qsort (v, c.cnt, sizeof (*v), (int (*) (const void *, const void *)) cmp);
*namelist = v;
}