X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fglob.c;h=24aec87f9155a02112b27e4eb1438a7a2d7199c5;hb=6c38d72875ec56c4b2c250717d458e70b2cb97ef;hp=1d31d77d0ef64618bf56f4993090a5bc659e7c84;hpb=12a195113bbb388bd4e911ff6b507252577b4805;p=gnulib.git diff --git a/lib/glob.c b/lib/glob.c index 1d31d77d0..24aec87f9 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007 +/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -32,6 +32,8 @@ /* #define NDEBUG 1 */ #include +#include + #include /* Needed on stupid SunOS for assert. */ #if !defined _LIBC || !defined GLOB_ONLY_P @@ -147,7 +149,6 @@ #ifndef _LIBC # include "dirfd.h" -# include "openat.h" #endif #ifdef _SC_GETPW_R_SIZE_MAX @@ -1218,13 +1219,17 @@ weak_alias (__glob_pattern_p, glob_pattern_p) #endif /* !GLOB_ONLY_P */ +#if !defined _LIBC || !defined GLOB_ONLY_P /* We put this in a separate function mainly to allow the memory allocated with alloca to be recycled. */ -#if !defined _LIBC || !defined GLOB_ONLY_P static int __attribute_noinline__ link_exists2_p (const char *dir, size_t dirlen, const char *fname, - glob_t *pglob) + glob_t *pglob +# if !defined _LIBC && !HAVE_FSTATAT + , int flags +# endif + ) { size_t fnamelen = strlen (fname); char *fullname = __alloca (dirlen + 1 + fnamelen + 1); @@ -1233,6 +1238,13 @@ link_exists2_p (const char *dir, size_t dirlen, const char *fname, mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1), fname, fnamelen + 1); +# if !defined _LIBC && !HAVE_FSTATAT + if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1)) + { + struct_stat64 st64; + return __stat64 (fullname, &st64) == 0; + } +# endif return (*pglob->gl_stat) (fullname, &st) == 0; } @@ -1241,6 +1253,7 @@ static int link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, glob_t *pglob, int flags) { +# if defined _LIBC || HAVE_FSTATAT if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) return link_exists2_p (dir, dirlen, fname, pglob); else @@ -1248,6 +1261,9 @@ link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, struct_stat64 st64; return __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0) == 0; } +# else + return link_exists2_p (dir, dirlen, fname, pglob, flags); +# endif } #endif @@ -1443,7 +1459,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags, while (1) { struct globnames *old = names; - for (size_t i = 0; i < cur; ++i) + size_t i; + for (i = 0; i < cur; ++i) free (names->name[i]); names = names->next; /* NB: we will not leak memory here if we exit without @@ -1468,7 +1485,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags, while (1) { struct globnames *old = names; - for (size_t i = 0; i < cur; ++i) + size_t i; + for (i = 0; i < cur; ++i) new_gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name[i]; names = names->next;