From bef4efb18c54f4b2285557a1b5a5a037f3dce019 Mon Sep 17 00:00:00 2001 From: "Peter S. Mazinger" Date: Wed, 16 Mar 2011 21:07:18 +0100 Subject: scandir,readdir[_t]: use one common source for X() and X64() Since the sources differ only minimally, use only scandir.c,readdir[_t].c and redefine the used functions accordingly. Use a strong_alias instead of compiling *64.c if __WORDSIZE = 64 Signed-off-by: Peter S. Mazinger Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/dirent/scandir.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'libc/misc/dirent/scandir.c') diff --git a/libc/misc/dirent/scandir.c b/libc/misc/dirent/scandir.c index bb425648b..c036ce59b 100644 --- a/libc/misc/dirent/scandir.c +++ b/libc/misc/dirent/scandir.c @@ -1,24 +1,29 @@ +/* vi: set sw=4 ts=4: */ /* - * Copyright (C) 2000-2006 Erik Andersen + * Copyright (C) 2000-2011 Erik Andersen * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ #include -#include #include #include #include -#include #include "dirstream.h" -int scandir(const char *dir, struct dirent ***namelist, - int (*selector) (const struct dirent *), - int (*compar) (const struct dirent **, const struct dirent **)) +#ifndef __SCANDIR +# define __SCANDIR scandir +# define __DIRENT_TYPE struct dirent +# define __READDIR readdir +#endif + +int __SCANDIR(const char *dir, __DIRENT_TYPE ***namelist, + int (*selector) (const __DIRENT_TYPE *), + int (*compar) (const __DIRENT_TYPE **, const __DIRENT_TYPE **)) { DIR *dp = opendir (dir); - struct dirent *current; - struct dirent **names = NULL; + __DIRENT_TYPE *current; + __DIRENT_TYPE **names = NULL; size_t names_size = 0, pos; int save; @@ -29,7 +34,7 @@ int scandir(const char *dir, struct dirent ***namelist, __set_errno (0); pos = 0; - while ((current = readdir (dp)) != NULL) { + while ((current = __READDIR (dp)) != NULL) { int use_it = selector == NULL; if (! use_it) @@ -43,7 +48,7 @@ int scandir(const char *dir, struct dirent ***namelist, } if (use_it) { - struct dirent *vnew; + __DIRENT_TYPE *vnew; size_t dsize; /* Ignore errors from selector or readdir */ @@ -51,24 +56,24 @@ int scandir(const char *dir, struct dirent ***namelist, if (unlikely(pos == names_size)) { - struct dirent **new; + __DIRENT_TYPE **new; if (names_size == 0) names_size = 10; else names_size *= 2; - new = (struct dirent **) realloc (names, - names_size * sizeof (struct dirent *)); + new = (__DIRENT_TYPE **) realloc (names, + names_size * sizeof (__DIRENT_TYPE *)); if (new == NULL) break; names = new; } dsize = ¤t->d_name[_D_ALLOC_NAMLEN(current)] - (char*)current; - vnew = (struct dirent *) malloc (dsize); + vnew = (__DIRENT_TYPE *) malloc (dsize); if (vnew == NULL) break; - names[pos++] = (struct dirent *) memcpy (vnew, current, dsize); + names[pos++] = (__DIRENT_TYPE *) memcpy (vnew, current, dsize); } } @@ -88,7 +93,10 @@ int scandir(const char *dir, struct dirent ***namelist, /* Sort the list if we have a comparison function to sort with. */ if (compar != NULL) - qsort (names, pos, sizeof (struct dirent *), (comparison_fn_t) compar); + qsort (names, pos, sizeof (__DIRENT_TYPE *), (comparison_fn_t) compar); *namelist = names; return pos; } +#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 +strong_alias_untyped(scandir,scandir64) +#endif -- cgit v1.2.3