version 1.18.10.1, 2010/08/05 01:46:31 |
version 1.26, 2010/07/06 14:59:22 |
Line 59 __RCSID("$NetBSD$"); |
|
Line 59 __RCSID("$NetBSD$"); |
|
* expand ~user/foo to the /home/dir/of/user/foo |
* expand ~user/foo to the /home/dir/of/user/foo |
* GLOB_BRACE: |
* GLOB_BRACE: |
* expand {1,2}{a,b} to 1a 1b 2a 2b |
* 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: |
* gl_matchc: |
* Number of matches in the current invocation of glob. |
* Number of matches in the current invocation of glob. |
*/ |
*/ |
Line 74 __RCSID("$NetBSD$"); |
|
Line 78 __RCSID("$NetBSD$"); |
|
#include <glob.h> |
#include <glob.h> |
#include <pwd.h> |
#include <pwd.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stddef.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
Line 593 glob2(Char *pathbuf, Char *pathend, Char |
|
Line 598 glob2(Char *pathbuf, Char *pathend, Char |
|
__gl_stat_t sb; |
__gl_stat_t sb; |
Char *p, *q; |
Char *p, *q; |
int anymeta; |
int anymeta; |
|
Char *pend; |
|
ptrdiff_t diff; |
|
|
_DIAGASSERT(pathbuf != NULL); |
_DIAGASSERT(pathbuf != NULL); |
_DIAGASSERT(pathend != NULL); |
_DIAGASSERT(pathend != NULL); |
Line 641 glob2(Char *pathbuf, Char *pathend, Char |
|
Line 648 glob2(Char *pathbuf, Char *pathend, Char |
|
*q++ = *p++; |
*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; |
pathend = q; |
pattern = p; |
pattern = p; |
while (*pattern == SEP) { |
while (*pattern == SEP) { |
Line 713 glob3(Char *pathbuf, Char *pathend, Char |
|
Line 739 glob3(Char *pathbuf, Char *pathend, Char |
|
u_char *sc; |
u_char *sc; |
Char *dc; |
Char *dc; |
|
|
/* Initial DOT must be matched literally. */ |
if ((pglob->gl_flags & GLOB_LIMIT) && |
if (dp->d_name[0] == DOT && *pattern != DOT) |
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; |
continue; |
/* |
/* |
* The resulting string contains EOS, so we can |
* The resulting string contains EOS, so we can |
Line 724 glob3(Char *pathbuf, Char *pathend, Char |
|
Line 770 glob3(Char *pathbuf, Char *pathend, Char |
|
dc <= pathlim && (*dc++ = *sc++) != EOS;) |
dc <= pathlim && (*dc++ = *sc++) != EOS;) |
continue; |
continue; |
|
|
if ((pglob->gl_flags & GLOB_LIMIT) && |
|
limit[GLOB_INDEX_READDIR]++ >= GLOB_LIMIT_READDIR) { |
|
errno = 0; |
|
*pathend++ = SEP; |
|
*pathend = EOS; |
|
return GLOB_NOSPACE; |
|
} |
|
|
|
/* |
/* |
* Have we filled the buffer without seeing EOS? |
* Have we filled the buffer without seeing EOS? |
*/ |
*/ |
Line 912 globfree(glob_t *pglob) |
|
Line 950 globfree(glob_t *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] != '\0') |
|
++pattern; |
|
break; |
|
|
|
case LBRACKET: |
|
range = 1; |
|
break; |
|
|
|
case RBRACKET: |
|
if (range) |
|
return 1; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
return 0; |
|
} |
|
#endif |
|
|
static DIR * |
static DIR * |
g_opendir(Char *str, glob_t *pglob) |
g_opendir(Char *str, glob_t *pglob) |
{ |
{ |