Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/glob.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/glob.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.14 retrieving revision 1.27 diff -u -p -r1.14 -r1.27 --- src/lib/libc/gen/glob.c 2005/11/29 03:11:59 1.14 +++ src/lib/libc/gen/glob.c 2010/09/06 14:40:25 1.27 @@ -1,4 +1,4 @@ -/* $NetBSD: glob.c,v 1.14 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: glob.c,v 1.27 2010/09/06 14:40:25 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #else -__RCSID("$NetBSD: glob.c,v 1.14 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: glob.c,v 1.27 2010/09/06 14:40:25 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,6 +59,10 @@ __RCSID("$NetBSD: glob.c,v 1.14 2005/11/ * expand ~user/foo to the /home/dir/of/user/foo * GLOB_BRACE: * expand {1,2}{a,b} to 1a 1b 2a 2b + * GLOB_PERIOD: + * allow metacharacters to match leading dots in filenames. + * GLOB_NO_DOTDIRS: + * . and .. are hidden from wildcards, even if GLOB_PERIOD is set. * gl_matchc: * Number of matches in the current invocation of glob. */ @@ -74,6 +78,7 @@ __RCSID("$NetBSD: glob.c,v 1.14 2005/11/ #include #include #include +#include #include #include #include @@ -82,6 +87,14 @@ __RCSID("$NetBSD: glob.c,v 1.14 2005/11/ #define NO_GETPW_R #endif +#define GLOB_LIMIT_MALLOC 65536 +#define GLOB_LIMIT_STAT 128 +#define GLOB_LIMIT_READDIR 16384 + +#define GLOB_INDEX_MALLOC 0 +#define GLOB_INDEX_STAT 1 +#define GLOB_INDEX_READDIR 2 + /* * XXX: For NetBSD 1.4.x compatibility. (kill me l8r) */ @@ -107,7 +120,7 @@ __RCSID("$NetBSD: glob.c,v 1.14 2005/11/ #define SLASH '/' #define COMMA ',' -#ifndef DEBUG +#ifndef USE_8BIT_CHARS #define M_QUOTE 0x8000 #define M_PROTECT 0x4000 @@ -118,10 +131,10 @@ typedef u_short Char; #else -#define M_QUOTE 0x80 -#define M_PROTECT 0x40 -#define M_MASK 0xff -#define M_ASCII 0x7f +#define M_QUOTE (Char)0x80 +#define M_PROTECT (Char)0x40 +#define M_MASK (Char)0xff +#define M_ASCII (Char)0x7f typedef char Char; @@ -139,36 +152,37 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) -static int compare __P((const void *, const void *)); -static int g_Ctoc __P((const Char *, char *, size_t)); -static int g_lstat __P((Char *, __gl_stat_t *, glob_t *)); -static DIR *g_opendir __P((Char *, glob_t *)); -static Char *g_strchr __P((const Char *, int)); -static int g_stat __P((Char *, __gl_stat_t *, glob_t *)); -static int glob0 __P((const Char *, glob_t *)); -static int glob1 __P((Char *, glob_t *, size_t *)); -static int glob2 __P((Char *, Char *, Char *, Char *, glob_t *, - size_t *)); -static int glob3 __P((Char *, Char *, Char *, Char *, Char *, glob_t *, - size_t *)); -static int globextend __P((const Char *, glob_t *, size_t *)); -static const Char *globtilde __P((const Char *, Char *, size_t, glob_t *)); -static int globexp1 __P((const Char *, glob_t *)); -static int globexp2 __P((const Char *, const Char *, glob_t *, int *)); -static int match __P((Char *, Char *, Char *)); +static int compare(const void *, const void *); +static int g_Ctoc(const Char *, char *, size_t); +static int g_lstat(Char *, __gl_stat_t *, glob_t *); +static DIR *g_opendir(Char *, glob_t *); +static Char *g_strchr(const Char *, int); +static int g_stat(Char *, __gl_stat_t *, glob_t *); +static int glob0(const Char *, glob_t *, size_t *); +static int glob1(Char *, glob_t *, size_t *); +static int glob2(Char *, Char *, Char *, const Char *, glob_t *, + size_t *); +static int glob3(Char *, Char *, Char *, const Char *, const Char *, + const Char *, glob_t *, size_t *); +static int globextend(const Char *, glob_t *, size_t *); +static const Char *globtilde(const Char *, Char *, size_t, glob_t *); +static int globexp1(const Char *, glob_t *, size_t *); +static int globexp2(const Char *, const Char *, glob_t *, int *, + size_t *); +static int match(const Char *, const Char *, const Char *); #ifdef DEBUG -static void qprintf __P((const char *, Char *)); +static void qprintf(const char *, Char *); #endif int -glob(pattern, flags, errfunc, pglob) - const char *pattern; - int flags, (*errfunc) __P((const char *, int)); - glob_t *pglob; +glob(const char *pattern, int flags, int (*errfunc)(const char *, int), + glob_t *pglob) { const u_char *patnext; int c; Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; + /* 0 = malloc(), 1 = stat(), 2 = readdir() */ + size_t limit[] = { 0, 0, 0 }; _DIAGASSERT(pattern != NULL); @@ -204,9 +218,9 @@ glob(pattern, flags, errfunc, pglob) *bufnext = EOS; if (flags & GLOB_BRACE) - return globexp1(patbuf, pglob); + return globexp1(patbuf, pglob, limit); else - return glob0(patbuf, pglob); + return glob0(patbuf, pglob, limit); } /* @@ -215,9 +229,7 @@ glob(pattern, flags, errfunc, pglob) * characters */ static int -globexp1(pattern, pglob) - const Char *pattern; - glob_t *pglob; +globexp1(const Char *pattern, glob_t *pglob, size_t *limit) { const Char* ptr = pattern; int rv; @@ -227,13 +239,13 @@ globexp1(pattern, pglob) /* Protect a single {}, for find(1), like csh */ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) - return glob0(pattern, pglob); + return glob0(pattern, pglob, limit); while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL) - if (!globexp2(ptr, pattern, pglob, &rv)) + if (!globexp2(ptr, pattern, pglob, &rv, limit)) return rv; - return glob0(pattern, pglob); + return glob0(pattern, pglob, limit); } @@ -243,10 +255,8 @@ globexp1(pattern, pglob) * If it fails then it tries to glob the rest of the pattern and returns. */ static int -globexp2(ptr, pattern, pglob, rv) - const Char *ptr, *pattern; - glob_t *pglob; - int *rv; +globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, + size_t *limit) { int i; Char *lm, *ls; @@ -291,7 +301,7 @@ globexp2(ptr, pattern, pglob, rv) * we use `pattern', not `patbuf' here so that that * unbalanced braces are passed to the match */ - *rv = glob0(pattern, pglob); + *rv = glob0(pattern, pglob, limit); return 0; } @@ -336,9 +346,9 @@ globexp2(ptr, pattern, pglob, rv) /* Expand the current pattern */ #ifdef DEBUG - qprintf("globexp2:", patbuf); + qprintf("globexp2", patbuf); #endif - *rv = globexp1(patbuf, pglob); + *rv = globexp1(patbuf, pglob, limit); /* move after the comma, to the next string */ pl = pm + 1; @@ -359,11 +369,7 @@ globexp2(ptr, pattern, pglob, rv) * expand tilde from the passwd file. */ static const Char * -globtilde(pattern, patbuf, patsize, pglob) - const Char *pattern; - Char *patbuf; - size_t patsize; - glob_t *pglob; +globtilde(const Char *pattern, Char *patbuf, size_t patsize, glob_t *pglob) { struct passwd *pwd; const char *h; @@ -455,14 +461,12 @@ globtilde(pattern, patbuf, patsize, pglo * to find no matches. */ static int -glob0(pattern, pglob) - const Char *pattern; - glob_t *pglob; +glob0(const Char *pattern, glob_t *pglob, size_t *limit) { const Char *qpatnext; - int c, error, oldpathc; + int c, error; + __gl_size_t oldpathc; Char *bufnext, patbuf[MAXPATHLEN+1]; - size_t limit = 0; _DIAGASSERT(pattern != NULL); _DIAGASSERT(pglob != NULL); @@ -509,10 +513,13 @@ glob0(pattern, pglob) break; case STAR: pglob->gl_flags |= GLOB_MAGCHAR; - /* collapse adjacent stars to one, + /* collapse adjacent stars to one [or three if globstar] * to avoid exponential behavior */ - if (bufnext == patbuf || bufnext[-1] != M_ALL) + if (bufnext == patbuf || bufnext[-1] != M_ALL || + ((pglob->gl_flags & GLOB_STAR) != 0 && + (bufnext - 1 == patbuf || bufnext[-2] != M_ALL || + bufnext - 2 == patbuf || bufnext[-3] != M_ALL))) *bufnext++ = M_ALL; break; default: @@ -522,11 +529,11 @@ glob0(pattern, pglob) } *bufnext = EOS; #ifdef DEBUG - qprintf("glob0:", patbuf); + qprintf("glob0", patbuf); #endif - if ((error = glob1(patbuf, pglob, &limit)) != 0) - return(error); + if ((error = glob1(patbuf, pglob, limit)) != 0) + return error; if (pglob->gl_pathc == oldpathc) { /* @@ -539,9 +546,9 @@ glob0(pattern, pglob) if ((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & (GLOB_NOMAGIC|GLOB_MAGCHAR)) == GLOB_NOMAGIC)) { - return globextend(pattern, pglob, &limit); + return globextend(pattern, pglob, limit); } else { - return (GLOB_NOMATCH); + return GLOB_NOMATCH; } } else if (!(pglob->gl_flags & GLOB_NOSORT)) { qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, @@ -549,25 +556,21 @@ glob0(pattern, pglob) compare); } - return(0); + return 0; } static int -compare(p, q) - const void *p, *q; +compare(const void *p, const void *q) { _DIAGASSERT(p != NULL); _DIAGASSERT(q != NULL); - return(strcoll(*(const char * const *)p, *(const char * const *)q)); + return strcoll(*(const char * const *)p, *(const char * const *)q); } static int -glob1(pattern, pglob, limit) - Char *pattern; - glob_t *pglob; - size_t *limit; +glob1(Char *pattern, glob_t *pglob, size_t *limit) { Char pathbuf[MAXPATHLEN+1]; @@ -576,15 +579,14 @@ glob1(pattern, pglob, limit) /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ if (*pattern == EOS) - return(0); + return 0; /* * we save one character so that we can use ptr >= limit, * in the general case when we are appending non nul chars only. */ - return(glob2(pathbuf, pathbuf, - pathbuf + (sizeof(pathbuf) / sizeof(*pathbuf)) - 1, - pattern, - pglob, limit)); + return glob2(pathbuf, pathbuf, + pathbuf + (sizeof(pathbuf) / sizeof(*pathbuf)) - 1, pattern, + pglob, limit); } /* @@ -593,20 +595,24 @@ glob1(pattern, pglob, limit) * meta characters. */ static int -glob2(pathbuf, pathend, pathlim, pattern, pglob, limit) - Char *pathbuf, *pathend, *pathlim, *pattern; - glob_t *pglob; - size_t *limit; +glob2(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern, + glob_t *pglob, size_t *limit) { __gl_stat_t sb; - Char *p, *q; + const Char *p; + Char *q; int anymeta; + Char *pend; + ptrdiff_t diff; _DIAGASSERT(pathbuf != NULL); _DIAGASSERT(pathend != NULL); _DIAGASSERT(pattern != NULL); _DIAGASSERT(pglob != NULL); +#ifdef DEBUG + qprintf("glob2", pathbuf); +#endif /* * Loop over pattern segments until end of pattern or until * segment with meta character found. @@ -615,20 +621,27 @@ glob2(pathbuf, pathend, pathlim, pattern if (*pattern == EOS) { /* End of pattern? */ *pathend = EOS; if (g_lstat(pathbuf, &sb, pglob)) - return(0); + return 0; + if ((pglob->gl_flags & GLOB_LIMIT) && + limit[GLOB_INDEX_STAT]++ >= GLOB_LIMIT_STAT) { + errno = 0; + *pathend++ = SEP; + *pathend = EOS; + return GLOB_NOSPACE; + } if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { if (pathend >= pathlim) - return (GLOB_ABORTED); + return GLOB_ABORTED; *pathend++ = SEP; *pathend = EOS; } ++pglob->gl_matchc; - return(globextend(pathbuf, pglob, limit)); + return globextend(pathbuf, pglob, limit); } /* Find end of next segment, copy tentatively to pathend. */ @@ -642,7 +655,26 @@ glob2(pathbuf, pathend, pathlim, pattern *q++ = *p++; } - if (!anymeta) { /* No expansion, do next segment. */ + /* + * No expansion, or path ends in slash-dot shash-dot-dot, + * do next segment. + */ + if (pglob->gl_flags & GLOB_PERIOD) { + for (pend = pathend; pend > pathbuf && pend[-1] == '/'; + pend--) + continue; + diff = pend - pathbuf; + } else { + /* XXX: GCC */ + diff = 0; + pend = pathend; + } + + if ((!anymeta) || + ((pglob->gl_flags & GLOB_PERIOD) && + (diff >= 1 && pend[-1] == DOT) && + (diff >= 2 && (pend[-2] == SLASH || pend[-2] == DOT)) && + (diff < 3 || pend[-3] == SLASH))) { pathend = q; pattern = p; while (*pattern == SEP) { @@ -651,22 +683,25 @@ glob2(pathbuf, pathend, pathlim, pattern *pathend++ = *pattern++; } } else /* Need expansion, recurse. */ - return(glob3(pathbuf, pathend, pathlim, pattern, p, - pglob, limit)); + return glob3(pathbuf, pathend, pathlim, pattern, p, + pattern, pglob, limit); } /* NOTREACHED */ } static int -glob3(pathbuf, pathend, pathlim, pattern, restpattern, pglob, limit) - Char *pathbuf, *pathend, *pathlim, *pattern, *restpattern; - glob_t *pglob; - size_t *limit; +glob3(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern, + const Char *restpattern, const Char *pglobstar, glob_t *pglob, + size_t *limit) { struct dirent *dp; DIR *dirp; + __gl_stat_t sbuf; int error; char buf[MAXPATHLEN]; + int globstar = 0; + int chase_symlinks = 0; + const Char *termstar = NULL; /* * The readdirfunc declaration can't be prototyped, because it is @@ -674,7 +709,7 @@ glob3(pathbuf, pathend, pathlim, pattern * and dirent.h as taking pointers to differently typed opaque * structures. */ - struct dirent *(*readdirfunc) __P((void *)); + struct dirent *(*readdirfunc)(void *); _DIAGASSERT(pathbuf != NULL); _DIAGASSERT(pathend != NULL); @@ -685,13 +720,46 @@ glob3(pathbuf, pathend, pathlim, pattern *pathend = EOS; errno = 0; + while (pglobstar < restpattern) { + if ((pglobstar[0] & M_MASK) == M_ALL && + (pglobstar[1] & M_MASK) == M_ALL) { + globstar = 1; + chase_symlinks = (pglobstar[2] & M_MASK) == M_ALL; + termstar = pglobstar + (2 + chase_symlinks); + break; + } + pglobstar++; + } + + if (globstar) { + error = pglobstar == pattern && termstar == restpattern ? + *restpattern == EOS ? + glob2(pathbuf, pathend, pathlim, restpattern - 1, pglob, + limit) : + glob2(pathbuf, pathend, pathlim, restpattern + 1, pglob, + limit) : + glob3(pathbuf, pathend, pathlim, pattern, restpattern, + termstar, pglob, limit); + if (error) + return error; + *pathend = EOS; + } + + if (*pathbuf && (g_lstat(pathbuf, &sbuf, pglob) || + !S_ISDIR(sbuf.st_mode) +#ifdef S_IFLINK + && ((globstar && !chase_symlinks) || !S_ISLNK(sbuf.st_mode)) +#endif + )) + return 0; + if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { if (pglob->gl_errfunc) { if (g_Ctoc(pathbuf, buf, sizeof(buf))) - return (GLOB_ABORTED); + return GLOB_ABORTED; if (pglob->gl_errfunc(buf, errno) || pglob->gl_flags & GLOB_ERR) - return (GLOB_ABORTED); + return GLOB_ABORTED; } /* * Posix/XOpen: glob should return when it encounters a @@ -700,9 +768,9 @@ glob3(pathbuf, pathend, pathlim, pattern * I think that Posix had in mind EPERM... */ if (pglob->gl_flags & GLOB_ERR) - return (GLOB_ABORTED); + return GLOB_ABORTED; - return(0); + return 0; } error = 0; @@ -716,8 +784,28 @@ glob3(pathbuf, pathend, pathlim, pattern u_char *sc; Char *dc; - /* Initial DOT must be matched literally. */ - if (dp->d_name[0] == DOT && *pattern != DOT) + if ((pglob->gl_flags & GLOB_LIMIT) && + limit[GLOB_INDEX_READDIR]++ >= GLOB_LIMIT_READDIR) { + errno = 0; + *pathend++ = SEP; + *pathend = EOS; + return GLOB_NOSPACE; + } + + /* + * Initial DOT must be matched literally, unless we have + * GLOB_PERIOD set. + */ + if ((pglob->gl_flags & GLOB_PERIOD) == 0) + if (dp->d_name[0] == DOT && *pattern != DOT) + continue; + /* + * If GLOB_NO_DOTDIRS is set, . and .. vanish. + */ + if ((pglob->gl_flags & GLOB_NO_DOTDIRS) && + (dp->d_name[0] == DOT) && + ((dp->d_name[1] == EOS) || + ((dp->d_name[1] == DOT) && (dp->d_name[2] == EOS)))) continue; /* * The resulting string contains EOS, so we can @@ -746,15 +834,36 @@ glob3(pathbuf, pathend, pathlim, pattern } } - if (!match(pathend, pattern, restpattern)) { + if (globstar) { +#ifdef S_IFLNK + if (!chase_symlinks && + (g_lstat(pathbuf, &sbuf, pglob) || + S_ISLNK(sbuf.st_mode))) + continue; +#endif + + if (!match(pathend, pattern, termstar)) + continue; + + if (--dc < pathlim - 2) + *dc++ = SEP; + *dc = EOS; + error = glob2(pathbuf, dc, pathlim, pglobstar, + pglob, limit); + if (error) + break; *pathend = EOS; - continue; + } else { + if (!match(pathend, pattern, restpattern)) { + *pathend = EOS; + continue; + } + error = glob2(pathbuf, --dc, pathlim, restpattern, + pglob, limit); + if (error) + break; } - error = glob2(pathbuf, --dc, pathlim, restpattern, pglob, limit); - if (error) - break; } - if (pglob->gl_flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir)(dirp); else @@ -764,14 +873,14 @@ glob3(pathbuf, pathend, pathlim, pattern * Again Posix X/Open issue with regards to error handling. */ if ((error || errno) && (pglob->gl_flags & GLOB_ERR)) - return (GLOB_ABORTED); + return GLOB_ABORTED; - return(error); + return error; } /* - * Extend the gl_pathv member of a glob_t structure to accomodate a new item, + * Extend the gl_pathv member of a glob_t structure to accommodate a new item, * add the new item, and update gl_pathc. * * This assumes the BSD realloc, which only copies the block when its size @@ -785,14 +894,10 @@ glob3(pathbuf, pathend, pathlim, pattern * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ static int -globextend(path, pglob, limit) - const Char *path; - glob_t *pglob; - size_t *limit; +globextend(const Char *path, glob_t *pglob, size_t *limit) { char **pathv; - int i; - size_t newsize, len; + size_t i, newsize, len; char *copy; const Char *p; @@ -803,12 +908,12 @@ globextend(path, pglob, limit) pathv = pglob->gl_pathv ? realloc(pglob->gl_pathv, newsize) : malloc(newsize); if (pathv == NULL) - return(GLOB_NOSPACE); + return GLOB_NOSPACE; if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { /* first time around -- clear initial gl_offs items */ pathv += pglob->gl_offs; - for (i = pglob->gl_offs; --i >= 0; ) + for (i = pglob->gl_offs + 1; --i > 0; ) *--pathv = NULL; } pglob->gl_pathv = pathv; @@ -816,22 +921,23 @@ globextend(path, pglob, limit) for (p = path; *p++;) continue; len = (size_t)(p - path); - *limit += len; + limit[GLOB_INDEX_MALLOC] += len; if ((copy = malloc(len)) != NULL) { if (g_Ctoc(path, copy, len)) { free(copy); - return(GLOB_ABORTED); + return GLOB_ABORTED; } pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; - if ((pglob->gl_flags & GLOB_LIMIT) && (newsize + *limit) >= ARG_MAX) { + if ((pglob->gl_flags & GLOB_LIMIT) && + (newsize + limit[GLOB_INDEX_MALLOC]) >= GLOB_LIMIT_MALLOC) { errno = 0; - return(GLOB_NOSPACE); + return GLOB_NOSPACE; } - return(copy == NULL ? GLOB_NOSPACE : 0); + return copy == NULL ? GLOB_NOSPACE : 0; } @@ -840,8 +946,7 @@ globextend(path, pglob, limit) * pattern causes a recursion level. */ static int -match(name, pat, patend) - Char *name, *pat, *patend; +match(const Char *name, const Char *pat, const Char *patend) { int ok, negate_range; Char c, k; @@ -854,21 +959,22 @@ match(name, pat, patend) c = *pat++; switch (c & M_MASK) { case M_ALL: + while (pat < patend && (*pat & M_MASK) == M_ALL) + pat++; /* eat consecutive '*' */ if (pat == patend) - return(1); - do - if (match(name, pat, patend)) - return(1); - while (*name++ != EOS); - return(0); + return 1; + for (; !match(name, pat, patend); name++) + if (*name == EOS) + return 0; + return 1; case M_ONE: if (*name++ == EOS) - return(0); + return 0; break; case M_SET: ok = 0; if ((k = *name++) == EOS) - return(0); + return 0; if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) ++pat; while (((c = *pat++) & M_MASK) != M_END) @@ -879,23 +985,22 @@ match(name, pat, patend) } else if (c == k) ok = 1; if (ok == negate_range) - return(0); + return 0; break; default: if (*name++ != c) - return(0); + return 0; break; } } - return(*name == EOS); + return *name == EOS; } /* Free allocated data belonging to a glob_t structure. */ void -globfree(pglob) - glob_t *pglob; +globfree(glob_t *pglob) { - int i; + size_t i; char **pp; _DIAGASSERT(pglob != NULL); @@ -911,10 +1016,41 @@ globfree(pglob) } } +#ifndef __LIBC12_SOURCE__ +int +glob_pattern_p(const char *pattern, int quote) +{ + int range = 0; + + for (; *pattern; pattern++) + switch (*pattern) { + case QUESTION: + case STAR: + return 1; + + case QUOTE: + if (quote && pattern[1] != EOS) + ++pattern; + break; + + case LBRACKET: + range = 1; + break; + + case RBRACKET: + if (range) + return 1; + break; + default: + break; + } + + return 0; +} +#endif + static DIR * -g_opendir(str, pglob) - Char *str; - glob_t *pglob; +g_opendir(Char *str, glob_t *pglob) { char buf[MAXPATHLEN]; @@ -929,16 +1065,13 @@ g_opendir(str, pglob) } if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_opendir)(buf)); + return (*pglob->gl_opendir)(buf); - return(opendir(buf)); + return opendir(buf); } static int -g_lstat(fn, sb, pglob) - Char *fn; - __gl_stat_t *sb; - glob_t *pglob; +g_lstat(Char *fn, __gl_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; @@ -949,15 +1082,12 @@ g_lstat(fn, sb, pglob) if (g_Ctoc(fn, buf, sizeof(buf))) return -1; if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_lstat)(buf, sb)); - return(lstat(buf, sb)); + return (*pglob->gl_lstat)(buf, sb); + return lstat(buf, sb); } static int -g_stat(fn, sb, pglob) - Char *fn; - __gl_stat_t *sb; - glob_t *pglob; +g_stat(Char *fn, __gl_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; @@ -968,14 +1098,12 @@ g_stat(fn, sb, pglob) if (g_Ctoc(fn, buf, sizeof(buf))) return -1; if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_stat)(buf, sb)); - return(stat(buf, sb)); + return (*pglob->gl_stat)(buf, sb); + return stat(buf, sb); } static Char * -g_strchr(str, ch) - const Char *str; - int ch; +g_strchr(const Char *str, int ch) { _DIAGASSERT(str != NULL); @@ -988,10 +1116,7 @@ g_strchr(str, ch) } static int -g_Ctoc(str, buf, len) - const Char *str; - char *buf; - size_t len; +g_Ctoc(const Char *str, char *buf, size_t len) { char *dc; @@ -1009,9 +1134,7 @@ g_Ctoc(str, buf, len) #ifdef DEBUG static void -qprintf(str, s) - const char *str; - Char *s; +qprintf(const char *str, Char *s) { Char *p;