| version 1.18.8.2, 2008/03/23 00:40:25 |
version 1.19, 2007/12/05 20:25:56 |
|
|
| /* glob.c,v 1.18.8.1 2008/01/09 01:34:05 matt Exp */ |
/* $NetBSD$ */ |
| |
|
| /* |
/* |
| * Copyright (c) 1989, 1993 |
* Copyright (c) 1989, 1993 |
|
|
| #if 0 |
#if 0 |
| static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; |
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; |
| #else |
#else |
| __RCSID("glob.c,v 1.18.8.1 2008/01/09 01:34:05 matt Exp"); |
__RCSID("$NetBSD$"); |
| #endif |
#endif |
| #endif /* LIBC_SCCS and not lint */ |
#endif /* LIBC_SCCS and not lint */ |
| |
|
| Line 61 __RCSID("glob.c,v 1.18.8.1 2008/01/09 01 |
|
| Line 61 __RCSID("glob.c,v 1.18.8.1 2008/01/09 01 |
|
| * expand {1,2}{a,b} to 1a 1b 2a 2b |
* expand {1,2}{a,b} to 1a 1b 2a 2b |
| * GLOB_PERIOD: |
* GLOB_PERIOD: |
| * allow metacharacters to match leading dots in filenames. |
* 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 78 __RCSID("glob.c,v 1.18.8.1 2008/01/09 01 |
|
| Line 76 __RCSID("glob.c,v 1.18.8.1 2008/01/09 01 |
|
| #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 587 glob2(Char *pathbuf, Char *pathend, Char |
|
| Line 584 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 630 glob2(Char *pathbuf, Char *pathend, Char |
|
| Line 625 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 729 glob3(Char *pathbuf, Char *pathend, Char |
|
| Line 705 glob3(Char *pathbuf, Char *pathend, Char |
|
| if (dp->d_name[0] == DOT && *pattern != DOT) |
if (dp->d_name[0] == DOT && *pattern != DOT) |
| continue; |
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 |
* The resulting string contains EOS, so we can |
| * use the pathlim character, if it is the nul |
* use the pathlim character, if it is the nul |
| */ |
*/ |