X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fglob.c;h=fcdee0bf7331f9a81d5c4eea015d20cb65a5e804;hb=cd56634a4a8179fd5a4419fbb3e27211b042ab1c;hp=f46159bd6543bdd5ec5dec00eacb02ba7e26f706;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/glob.c b/lib/glob.c index f46159bd6..fcdee0bf7 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. +/* Copyright (C) 1991-2014 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 @@ -16,6 +15,9 @@ along with this program. If not, see . */ #ifndef _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the pattern == NULL || pglob == NULL tests below. */ +# define _GL_ARG_NONNULL(params) # include #endif @@ -63,7 +65,7 @@ #endif /* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available - if the `d_type' member for `struct dirent' is available. + if the 'd_type' member for 'struct dirent' is available. HAVE_STRUCT_DIRENT_D_TYPE plays the same role in GNULIB. */ #if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE /* True if the directory entry D must be of type T. */ @@ -83,7 +85,7 @@ # define DIRENT_MIGHT_BE_DIR(d) true #endif /* HAVE_D_TYPE */ -/* If the system has the `struct dirent64' type we use it internally. */ +/* If the system has the 'struct dirent64' type we use it internally. */ #if defined _LIBC && !defined COMPILE_GLOB64 # if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__ # define CONVERT_D_INO(d64, d32) @@ -142,10 +144,8 @@ # define __stat64(fname, buf) stat (fname, buf) # define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag) # define struct_stat64 struct stat -# define __stat(fname, buf) stat (fname, buf) # define __alloca alloca # define __readdir readdir -# define __readdir64 readdir64 # define __glob_pattern_p glob_pattern_p #endif /* _LIBC */ @@ -162,7 +162,7 @@ # define GET_LOGIN_NAME_MAX() (-1) #endif -static const char *next_brace_sub (const char *begin, int flags) __THROW; +static const char *next_brace_sub (const char *begin, int flags) __THROWNL; #endif /* !defined _LIBC || !defined GLOB_ONLY_P */ @@ -210,8 +210,8 @@ extern int __glob_pattern_type (const char *pattern, int quote) attribute_hidden; #if !defined _LIBC || !defined GLOB_ONLY_P -static int prefix_array (const char *prefix, char **array, size_t n) __THROW; -static int collated_compare (const void *, const void *) __THROW; +static int prefix_array (const char *prefix, char **array, size_t n) __THROWNL; +static int collated_compare (const void *, const void *) __THROWNL; /* Find the end of the sub-pattern in a brace expression. */ @@ -244,10 +244,10 @@ next_brace_sub (const char *cp, int flags) The bits defined above may be set in FLAGS. If a directory cannot be opened or read and ERRFUNC is not nil, it is called with the pathname that caused the error, and the - `errno' value from the failing call; if it returns non-zero - `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. + 'errno' value from the failing call; if it returns non-zero + 'glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. - Otherwise, `glob' returns zero. */ + Otherwise, 'glob' returns zero. */ int #ifdef GLOB_ATTRIBUTE GLOB_ATTRIBUTE @@ -274,7 +274,7 @@ glob (pattern, flags, errfunc, pglob) } if (!(flags & GLOB_DOOFFS)) - /* Have to do this so `globfree' knows where to start freeing. It + /* Have to do this so 'globfree' knows where to start freeing. It also makes all the code that uses gl_offs simpler. */ pglob->gl_offs = 0; @@ -427,7 +427,7 @@ glob (pattern, flags, errfunc, pglob) /* Find the filename. */ filename = strrchr (pattern, '/'); #if defined __MSDOS__ || defined WINDOWS32 - /* The case of "d:pattern". Since `:' is not allowed in + /* The case of "d:pattern". Since ':' is not allowed in file names, we can safely assume that wherever it happens in pattern, it signals the filename part. This is so we could some day support patterns like "[a-z]:foo". */ @@ -486,7 +486,7 @@ glob (pattern, flags, errfunc, pglob) prevent infinite recursion in glob. */ if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) return GLOB_NOMATCH; - /* If this is "d:pattern", we need to copy `:' to DIRNAME + /* If this is "d:pattern", we need to copy ':' to DIRNAME as well. If it's "d:/pattern", don't remove the slash from "d:/", since "d:" and "d:/" are not the same.*/ } @@ -596,7 +596,7 @@ glob (pattern, flags, errfunc, pglob) size_t buflen = GET_LOGIN_NAME_MAX () + 1; if (buflen == 0) - /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try + /* 'sysconf' does not support _SC_LOGIN_NAME_MAX. Try a moderate value. */ buflen = 20; name = __alloca (buflen); @@ -613,7 +613,7 @@ glob (pattern, flags, errfunc, pglob) # ifndef _LIBC if (pwbuflen == -1) - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. + /* 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a moderate value. */ pwbuflen = 1024; # endif @@ -738,7 +738,7 @@ glob (pattern, flags, errfunc, pglob) # ifndef _LIBC if (buflen == -1) - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a + /* 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a moderate value. */ buflen = 1024; # endif @@ -943,7 +943,7 @@ glob (pattern, flags, errfunc, pglob) flags |= GLOB_MAGCHAR; - /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls. + /* We have ignored the GLOB_NOCHECK flag in the 'glob_in_dir' calls. But if we have not found any matching entry and the GLOB_NOCHECK flag was set we must return the input pattern itself. */ if (pglob->gl_pathc + pglob->gl_offs == oldcount) @@ -1088,7 +1088,7 @@ libc_hidden_def (glob) #if !defined _LIBC || !defined GLOB_ONLY_P -/* Free storage allocated in PGLOB by a previous `glob' call. */ +/* Free storage allocated in PGLOB by a previous 'glob' call. */ void globfree (pglob) register glob_t *pglob; @@ -1153,7 +1153,7 @@ prefix_array (const char *dirname, char **array, size_t n) --dirlen; else if (dirname[dirlen - 1] == ':') { - /* DIRNAME is "d:". Use `:' instead of `/'. */ + /* DIRNAME is "d:". Use ':' instead of '/'. */ --dirlen; sep_char = ':'; } @@ -1279,6 +1279,8 @@ link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, return link_exists2_p (dir, dirlen, fname, pglob); else { + /* dfd cannot be -1 here, because dirfd never returns -1 on + glibc, or on hosts that have fstatat. */ struct_stat64 st64; return __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0) == 0; } @@ -1289,7 +1291,7 @@ link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, #endif -/* Like `glob', but PATTERN is a final pathname component, +/* Like 'glob', but PATTERN is a final pathname component, and matches are searched for in DIRECTORY. The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. The GLOB_APPEND flag is assumed to be set (always appends). */