| version 1.25, 2010/07/02 21:13:10 |
version 1.26, 2010/07/06 14:59:22 |
| Line 87 __RCSID("$NetBSD$"); |
|
| Line 87 __RCSID("$NetBSD$"); |
|
| #define NO_GETPW_R |
#define NO_GETPW_R |
| #endif |
#endif |
| |
|
| #if !defined(ARG_MAX) |
#define GLOB_LIMIT_MALLOC 65536 |
| #include <limits.h> |
#define GLOB_LIMIT_STAT 128 |
| #define ARG_MAX _POSIX_ARG_MAX |
#define GLOB_LIMIT_READDIR 16384 |
| #endif |
|
| |
#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) |
* XXX: For NetBSD 1.4.x compatibility. (kill me l8r) |
| Line 178 glob(const char *pattern, int flags, int |
|
| Line 181 glob(const char *pattern, int flags, int |
|
| const u_char *patnext; |
const u_char *patnext; |
| int c; |
int c; |
| Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; |
Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; |
| size_t limit = 0; |
/* 0 = malloc(), 1 = stat(), 2 = readdir() */ |
| |
size_t limit[] = { 0, 0, 0 }; |
| |
|
| _DIAGASSERT(pattern != NULL); |
_DIAGASSERT(pattern != NULL); |
| |
|
| Line 214 glob(const char *pattern, int flags, int |
|
| Line 218 glob(const char *pattern, int flags, int |
|
| *bufnext = EOS; |
*bufnext = EOS; |
| |
|
| if (flags & GLOB_BRACE) |
if (flags & GLOB_BRACE) |
| return globexp1(patbuf, pglob, &limit); |
return globexp1(patbuf, pglob, limit); |
| else |
else |
| return glob0(patbuf, pglob, &limit); |
return glob0(patbuf, pglob, limit); |
| } |
} |
| |
|
| /* |
/* |
| Line 612 glob2(Char *pathbuf, Char *pathend, Char |
|
| Line 616 glob2(Char *pathbuf, Char *pathend, Char |
|
| if (g_lstat(pathbuf, &sb, pglob)) |
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) && |
if (((pglob->gl_flags & GLOB_MARK) && |
| pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || |
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || |
| (S_ISLNK(sb.st_mode) && |
(S_ISLNK(sb.st_mode) && |
| Line 728 glob3(Char *pathbuf, Char *pathend, Char |
|
| Line 739 glob3(Char *pathbuf, Char *pathend, Char |
|
| u_char *sc; |
u_char *sc; |
| Char *dc; |
Char *dc; |
| |
|
| |
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 |
* Initial DOT must be matched literally, unless we have |
| * GLOB_PERIOD set. |
* GLOB_PERIOD set. |
| Line 774 glob3(Char *pathbuf, Char *pathend, Char |
|
| Line 793 glob3(Char *pathbuf, Char *pathend, Char |
|
| *pathend = EOS; |
*pathend = EOS; |
| continue; |
continue; |
| } |
} |
| error = glob2(pathbuf, --dc, pathlim, restpattern, pglob, limit); |
error = glob2(pathbuf, --dc, pathlim, restpattern, pglob, |
| |
limit); |
| if (error) |
if (error) |
| break; |
break; |
| } |
} |
| Line 836 globextend(const Char *path, glob_t *pgl |
|
| Line 856 globextend(const Char *path, glob_t *pgl |
|
| for (p = path; *p++;) |
for (p = path; *p++;) |
| continue; |
continue; |
| len = (size_t)(p - path); |
len = (size_t)(p - path); |
| *limit += len; |
limit[GLOB_INDEX_MALLOC] += len; |
| if ((copy = malloc(len)) != NULL) { |
if ((copy = malloc(len)) != NULL) { |
| if (g_Ctoc(path, copy, len)) { |
if (g_Ctoc(path, copy, len)) { |
| free(copy); |
free(copy); |
| Line 846 globextend(const Char *path, glob_t *pgl |
|
| Line 866 globextend(const Char *path, glob_t *pgl |
|
| } |
} |
| pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
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; |
errno = 0; |
| return GLOB_NOSPACE; |
return GLOB_NOSPACE; |
| } |
} |