|
Lines 129-140
typedef char Char;
Link Here
|
| 129 |
#define M_CLASS META(':') |
129 |
#define M_CLASS META(':') |
| 130 |
#define ismeta(c) (((c)&M_QUOTE) != 0) |
130 |
#define ismeta(c) (((c)&M_QUOTE) != 0) |
| 131 |
|
131 |
|
| 132 |
#define GLOB_LIMIT_MALLOC 65536 |
132 |
#define COMPAT_GLOB_LIMIT_MALLOC 65536 |
| 133 |
#define GLOB_LIMIT_STAT 128 |
133 |
#define COMPAT_GLOB_LIMIT_STAT 128 |
| 134 |
#define GLOB_LIMIT_READDIR 16384 |
134 |
#define COMPAT_GLOB_LIMIT_READDIR 16384 |
| 135 |
|
135 |
|
| 136 |
/* Limit of recursion during matching attempts. */ |
136 |
/* Limit of recursion during matching attempts. */ |
| 137 |
#define GLOB_LIMIT_RECUR 64 |
137 |
#define COMPAT_GLOB_LIMIT_RECUR 64 |
| 138 |
|
138 |
|
| 139 |
struct glob_lim { |
139 |
struct glob_lim { |
| 140 |
size_t glim_malloc; |
140 |
size_t glim_malloc; |
|
Lines 150-172
struct glob_path_stat {
Link Here
|
| 150 |
static int compare(const void *, const void *); |
150 |
static int compare(const void *, const void *); |
| 151 |
static int compare_gps(const void *, const void *); |
151 |
static int compare_gps(const void *, const void *); |
| 152 |
static int g_Ctoc(const Char *, char *, u_int); |
152 |
static int g_Ctoc(const Char *, char *, u_int); |
| 153 |
static int g_lstat(Char *, struct stat *, glob_t *); |
153 |
static int g_lstat(Char *, struct stat *, compat_glob_t *); |
| 154 |
static DIR *g_opendir(Char *, glob_t *); |
154 |
static DIR *g_opendir(Char *, compat_glob_t *); |
| 155 |
static Char *g_strchr(const Char *, int); |
155 |
static Char *g_strchr(const Char *, int); |
| 156 |
static int g_strncmp(const Char *, const char *, size_t); |
156 |
static int g_strncmp(const Char *, const char *, size_t); |
| 157 |
static int g_stat(Char *, struct stat *, glob_t *); |
157 |
static int g_stat(Char *, struct stat *, compat_glob_t *); |
| 158 |
static int glob0(const Char *, glob_t *, struct glob_lim *); |
158 |
static int glob0(const Char *, compat_glob_t *, struct glob_lim *); |
| 159 |
static int glob1(Char *, Char *, glob_t *, struct glob_lim *); |
159 |
static int glob1(Char *, Char *, compat_glob_t *, struct glob_lim *); |
| 160 |
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, |
160 |
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, |
| 161 |
glob_t *, struct glob_lim *); |
161 |
compat_glob_t *, struct glob_lim *); |
| 162 |
static int glob3(Char *, Char *, Char *, Char *, Char *, |
162 |
static int glob3(Char *, Char *, Char *, Char *, Char *, |
| 163 |
Char *, Char *, glob_t *, struct glob_lim *); |
163 |
Char *, Char *, compat_glob_t *, struct glob_lim *); |
| 164 |
static int globextend(const Char *, glob_t *, struct glob_lim *, |
164 |
static int globextend(const Char *, compat_glob_t *, struct glob_lim *, |
| 165 |
struct stat *); |
165 |
struct stat *); |
| 166 |
static const Char * |
166 |
static const Char * |
| 167 |
globtilde(const Char *, Char *, size_t, glob_t *); |
167 |
globtilde(const Char *, Char *, size_t, compat_glob_t *); |
| 168 |
static int globexp1(const Char *, glob_t *, struct glob_lim *); |
168 |
static int globexp1(const Char *, compat_glob_t *, struct glob_lim *); |
| 169 |
static int globexp2(const Char *, const Char *, glob_t *, |
169 |
static int globexp2(const Char *, const Char *, compat_glob_t *, |
| 170 |
struct glob_lim *); |
170 |
struct glob_lim *); |
| 171 |
static int match(Char *, Char *, Char *, int); |
171 |
static int match(Char *, Char *, Char *, int); |
| 172 |
#ifdef DEBUG |
172 |
#ifdef DEBUG |
|
Lines 174-181
static void qprintf(const char *, Char *);
Link Here
|
| 174 |
#endif |
174 |
#endif |
| 175 |
|
175 |
|
| 176 |
int |
176 |
int |
| 177 |
glob(const char *pattern, int flags, int (*errfunc)(const char *, int), |
177 |
compat_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), |
| 178 |
glob_t *pglob) |
178 |
compat_glob_t *pglob) |
| 179 |
{ |
179 |
{ |
| 180 |
const u_char *patnext; |
180 |
const u_char *patnext; |
| 181 |
int c; |
181 |
int c; |
|
Lines 183-210
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
Link Here
|
| 183 |
struct glob_lim limit = { 0, 0, 0 }; |
183 |
struct glob_lim limit = { 0, 0, 0 }; |
| 184 |
|
184 |
|
| 185 |
if (strnlen(pattern, PATH_MAX) == PATH_MAX) |
185 |
if (strnlen(pattern, PATH_MAX) == PATH_MAX) |
| 186 |
return(GLOB_NOMATCH); |
186 |
return(COMPAT_GLOB_NOMATCH); |
| 187 |
|
187 |
|
| 188 |
patnext = (u_char *) pattern; |
188 |
patnext = (u_char *) pattern; |
| 189 |
if (!(flags & GLOB_APPEND)) { |
189 |
if (!(flags & COMPAT_GLOB_APPEND)) { |
| 190 |
pglob->gl_pathc = 0; |
190 |
pglob->gl_pathc = 0; |
| 191 |
pglob->gl_pathv = NULL; |
191 |
pglob->gl_pathv = NULL; |
| 192 |
pglob->gl_statv = NULL; |
192 |
pglob->gl_statv = NULL; |
| 193 |
if (!(flags & GLOB_DOOFFS)) |
193 |
if (!(flags & COMPAT_GLOB_DOOFFS)) |
| 194 |
pglob->gl_offs = 0; |
194 |
pglob->gl_offs = 0; |
| 195 |
} |
195 |
} |
| 196 |
pglob->gl_flags = flags & ~GLOB_MAGCHAR; |
196 |
pglob->gl_flags = flags & ~COMPAT_GLOB_MAGCHAR; |
| 197 |
pglob->gl_errfunc = errfunc; |
197 |
pglob->gl_errfunc = errfunc; |
| 198 |
pglob->gl_matchc = 0; |
198 |
pglob->gl_matchc = 0; |
| 199 |
|
199 |
|
| 200 |
if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || |
200 |
if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || |
| 201 |
pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || |
201 |
pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || |
| 202 |
pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) |
202 |
pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) |
| 203 |
return GLOB_NOSPACE; |
203 |
return COMPAT_GLOB_NOSPACE; |
| 204 |
|
204 |
|
| 205 |
bufnext = patbuf; |
205 |
bufnext = patbuf; |
| 206 |
bufend = bufnext + MAXPATHLEN - 1; |
206 |
bufend = bufnext + MAXPATHLEN - 1; |
| 207 |
if (flags & GLOB_NOESCAPE) |
207 |
if (flags & COMPAT_GLOB_NOESCAPE) |
| 208 |
while (bufnext < bufend && (c = *patnext++) != EOS) |
208 |
while (bufnext < bufend && (c = *patnext++) != EOS) |
| 209 |
*bufnext++ = c; |
209 |
*bufnext++ = c; |
| 210 |
else { |
210 |
else { |
|
Lines 221-227
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
Link Here
|
| 221 |
} |
221 |
} |
| 222 |
*bufnext = EOS; |
222 |
*bufnext = EOS; |
| 223 |
|
223 |
|
| 224 |
if (flags & GLOB_BRACE) |
224 |
if (flags & COMPAT_GLOB_BRACE) |
| 225 |
return globexp1(patbuf, pglob, &limit); |
225 |
return globexp1(patbuf, pglob, &limit); |
| 226 |
else |
226 |
else |
| 227 |
return glob0(patbuf, pglob, &limit); |
227 |
return glob0(patbuf, pglob, &limit); |
|
Lines 233-239
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
Link Here
|
| 233 |
* characters |
233 |
* characters |
| 234 |
*/ |
234 |
*/ |
| 235 |
static int |
235 |
static int |
| 236 |
globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) |
236 |
globexp1(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp) |
| 237 |
{ |
237 |
{ |
| 238 |
const Char* ptr = pattern; |
238 |
const Char* ptr = pattern; |
| 239 |
|
239 |
|
|
Lines 254-260
globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 254 |
* If it fails then it tries to glob the rest of the pattern and returns. |
254 |
* If it fails then it tries to glob the rest of the pattern and returns. |
| 255 |
*/ |
255 |
*/ |
| 256 |
static int |
256 |
static int |
| 257 |
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, |
257 |
globexp2(const Char *ptr, const Char *pattern, compat_glob_t *pglob, |
| 258 |
struct glob_lim *limitp) |
258 |
struct glob_lim *limitp) |
| 259 |
{ |
259 |
{ |
| 260 |
int i, rv; |
260 |
int i, rv; |
|
Lines 338-344
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
Link Here
|
| 338 |
qprintf("globexp2:", patbuf); |
338 |
qprintf("globexp2:", patbuf); |
| 339 |
#endif |
339 |
#endif |
| 340 |
rv = globexp1(patbuf, pglob, limitp); |
340 |
rv = globexp1(patbuf, pglob, limitp); |
| 341 |
if (rv && rv != GLOB_NOMATCH) |
341 |
if (rv && rv != COMPAT_GLOB_NOMATCH) |
| 342 |
return rv; |
342 |
return rv; |
| 343 |
|
343 |
|
| 344 |
/* move after the comma, to the next string */ |
344 |
/* move after the comma, to the next string */ |
|
Lines 359-372
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
Link Here
|
| 359 |
* expand tilde from the passwd file. |
359 |
* expand tilde from the passwd file. |
| 360 |
*/ |
360 |
*/ |
| 361 |
static const Char * |
361 |
static const Char * |
| 362 |
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) |
362 |
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, compat_glob_t *pglob) |
| 363 |
{ |
363 |
{ |
| 364 |
struct passwd *pwd; |
364 |
struct passwd *pwd; |
| 365 |
char *h; |
365 |
char *h; |
| 366 |
const Char *p; |
366 |
const Char *p; |
| 367 |
Char *b, *eb; |
367 |
Char *b, *eb; |
| 368 |
|
368 |
|
| 369 |
if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) |
369 |
if (*pattern != TILDE || !(pglob->gl_flags & COMPAT_GLOB_TILDE)) |
| 370 |
return pattern; |
370 |
return pattern; |
| 371 |
|
371 |
|
| 372 |
/* Copy up to the end of the string or / */ |
372 |
/* Copy up to the end of the string or / */ |
|
Lines 468-474
g_charclass(const Char **patternp, Char **bufnextp)
Link Here
|
| 468 |
* to find no matches. |
468 |
* to find no matches. |
| 469 |
*/ |
469 |
*/ |
| 470 |
static int |
470 |
static int |
| 471 |
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) |
471 |
glob0(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp) |
| 472 |
{ |
472 |
{ |
| 473 |
const Char *qpatnext; |
473 |
const Char *qpatnext; |
| 474 |
int c, err, oldpathc; |
474 |
int c, err, oldpathc; |
|
Lines 506-513
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 506 |
c = *qpatnext++; |
506 |
c = *qpatnext++; |
| 507 |
} while (c == LBRACKET && *qpatnext == ':'); |
507 |
} while (c == LBRACKET && *qpatnext == ':'); |
| 508 |
if (err == -1 && |
508 |
if (err == -1 && |
| 509 |
!(pglob->gl_flags & GLOB_NOCHECK)) |
509 |
!(pglob->gl_flags & COMPAT_GLOB_NOCHECK)) |
| 510 |
return GLOB_NOMATCH; |
510 |
return COMPAT_GLOB_NOMATCH; |
| 511 |
if (c == RBRACKET) |
511 |
if (c == RBRACKET) |
| 512 |
break; |
512 |
break; |
| 513 |
} |
513 |
} |
|
Lines 519-533
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 519 |
qpatnext += 2; |
519 |
qpatnext += 2; |
| 520 |
} |
520 |
} |
| 521 |
} while ((c = *qpatnext++) != RBRACKET); |
521 |
} while ((c = *qpatnext++) != RBRACKET); |
| 522 |
pglob->gl_flags |= GLOB_MAGCHAR; |
522 |
pglob->gl_flags |= COMPAT_GLOB_MAGCHAR; |
| 523 |
*bufnext++ = M_END; |
523 |
*bufnext++ = M_END; |
| 524 |
break; |
524 |
break; |
| 525 |
case QUESTION: |
525 |
case QUESTION: |
| 526 |
pglob->gl_flags |= GLOB_MAGCHAR; |
526 |
pglob->gl_flags |= COMPAT_GLOB_MAGCHAR; |
| 527 |
*bufnext++ = M_ONE; |
527 |
*bufnext++ = M_ONE; |
| 528 |
break; |
528 |
break; |
| 529 |
case STAR: |
529 |
case STAR: |
| 530 |
pglob->gl_flags |= GLOB_MAGCHAR; |
530 |
pglob->gl_flags |= COMPAT_GLOB_MAGCHAR; |
| 531 |
/* collapse adjacent stars to one, |
531 |
/* collapse adjacent stars to one, |
| 532 |
* to avoid exponential behavior |
532 |
* to avoid exponential behavior |
| 533 |
*/ |
533 |
*/ |
|
Lines 554-568
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 554 |
* GLOB_NOMAGIC is there just for compatibility with csh. |
554 |
* GLOB_NOMAGIC is there just for compatibility with csh. |
| 555 |
*/ |
555 |
*/ |
| 556 |
if (pglob->gl_pathc == oldpathc) { |
556 |
if (pglob->gl_pathc == oldpathc) { |
| 557 |
if ((pglob->gl_flags & GLOB_NOCHECK) || |
557 |
if ((pglob->gl_flags & COMPAT_GLOB_NOCHECK) || |
| 558 |
((pglob->gl_flags & GLOB_NOMAGIC) && |
558 |
((pglob->gl_flags & COMPAT_GLOB_NOMAGIC) && |
| 559 |
!(pglob->gl_flags & GLOB_MAGCHAR))) |
559 |
!(pglob->gl_flags & COMPAT_GLOB_MAGCHAR))) |
| 560 |
return(globextend(pattern, pglob, limitp, NULL)); |
560 |
return(globextend(pattern, pglob, limitp, NULL)); |
| 561 |
else |
561 |
else |
| 562 |
return(GLOB_NOMATCH); |
562 |
return(COMPAT_GLOB_NOMATCH); |
| 563 |
} |
563 |
} |
| 564 |
if (!(pglob->gl_flags & GLOB_NOSORT)) { |
564 |
if (!(pglob->gl_flags & COMPAT_GLOB_NOSORT)) { |
| 565 |
if ((pglob->gl_flags & GLOB_KEEPSTAT)) { |
565 |
if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT)) { |
| 566 |
/* Keep the paths and stat info synced during sort */ |
566 |
/* Keep the paths and stat info synced during sort */ |
| 567 |
struct glob_path_stat *path_stat; |
567 |
struct glob_path_stat *path_stat; |
| 568 |
int i; |
568 |
int i; |
|
Lines 570-576
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 570 |
int o = pglob->gl_offs + oldpathc; |
570 |
int o = pglob->gl_offs + oldpathc; |
| 571 |
|
571 |
|
| 572 |
if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) |
572 |
if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) |
| 573 |
return GLOB_NOSPACE; |
573 |
return COMPAT_GLOB_NOSPACE; |
| 574 |
for (i = 0; i < n; i++) { |
574 |
for (i = 0; i < n; i++) { |
| 575 |
path_stat[i].gps_path = pglob->gl_pathv[o + i]; |
575 |
path_stat[i].gps_path = pglob->gl_pathv[o + i]; |
| 576 |
path_stat[i].gps_stat = pglob->gl_statv[o + i]; |
576 |
path_stat[i].gps_stat = pglob->gl_statv[o + i]; |
|
Lines 606-612
compare_gps(const void *_p, const void *_q)
Link Here
|
| 606 |
} |
606 |
} |
| 607 |
|
607 |
|
| 608 |
static int |
608 |
static int |
| 609 |
glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) |
609 |
glob1(Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp) |
| 610 |
{ |
610 |
{ |
| 611 |
Char pathbuf[MAXPATHLEN]; |
611 |
Char pathbuf[MAXPATHLEN]; |
| 612 |
|
612 |
|
|
Lines 625-631
glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
Link Here
|
| 625 |
*/ |
625 |
*/ |
| 626 |
static int |
626 |
static int |
| 627 |
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
627 |
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
| 628 |
Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) |
628 |
Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp) |
| 629 |
{ |
629 |
{ |
| 630 |
struct stat sb; |
630 |
struct stat sb; |
| 631 |
Char *p, *q; |
631 |
Char *p, *q; |
|
Lines 641-655
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 641 |
if (g_lstat(pathbuf, &sb, pglob)) |
641 |
if (g_lstat(pathbuf, &sb, pglob)) |
| 642 |
return(0); |
642 |
return(0); |
| 643 |
|
643 |
|
| 644 |
if ((pglob->gl_flags & GLOB_LIMIT) && |
644 |
if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) && |
| 645 |
limitp->glim_stat++ >= GLOB_LIMIT_STAT) { |
645 |
limitp->glim_stat++ >= COMPAT_GLOB_LIMIT_STAT) { |
| 646 |
errno = 0; |
646 |
errno = 0; |
| 647 |
*pathend++ = SEP; |
647 |
*pathend++ = SEP; |
| 648 |
*pathend = EOS; |
648 |
*pathend = EOS; |
| 649 |
return(GLOB_NOSPACE); |
649 |
return(COMPAT_GLOB_NOSPACE); |
| 650 |
} |
650 |
} |
| 651 |
|
651 |
|
| 652 |
if (((pglob->gl_flags & GLOB_MARK) && |
652 |
if (((pglob->gl_flags & COMPAT_GLOB_MARK) && |
| 653 |
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || |
653 |
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || |
| 654 |
(S_ISLNK(sb.st_mode) && |
654 |
(S_ISLNK(sb.st_mode) && |
| 655 |
(g_stat(pathbuf, &sb, pglob) == 0) && |
655 |
(g_stat(pathbuf, &sb, pglob) == 0) && |
|
Lines 693-699
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 693 |
|
693 |
|
| 694 |
static int |
694 |
static int |
| 695 |
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
695 |
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
| 696 |
Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, |
696 |
Char *pattern, Char *restpattern, Char *restpattern_last, compat_glob_t *pglob, |
| 697 |
struct glob_lim *limitp) |
697 |
struct glob_lim *limitp) |
| 698 |
{ |
698 |
{ |
| 699 |
struct dirent *dp; |
699 |
struct dirent *dp; |
|
Lines 718-727
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 718 |
/* TODO: don't call for ENOENT or ENOTDIR? */ |
718 |
/* TODO: don't call for ENOENT or ENOTDIR? */ |
| 719 |
if (pglob->gl_errfunc) { |
719 |
if (pglob->gl_errfunc) { |
| 720 |
if (g_Ctoc(pathbuf, buf, sizeof(buf))) |
720 |
if (g_Ctoc(pathbuf, buf, sizeof(buf))) |
| 721 |
return(GLOB_ABORTED); |
721 |
return(COMPAT_GLOB_ABORTED); |
| 722 |
if (pglob->gl_errfunc(buf, errno) || |
722 |
if (pglob->gl_errfunc(buf, errno) || |
| 723 |
pglob->gl_flags & GLOB_ERR) |
723 |
pglob->gl_flags & COMPAT_GLOB_ERR) |
| 724 |
return(GLOB_ABORTED); |
724 |
return(COMPAT_GLOB_ABORTED); |
| 725 |
} |
725 |
} |
| 726 |
return(0); |
726 |
return(0); |
| 727 |
} |
727 |
} |
|
Lines 729-735
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 729 |
err = 0; |
729 |
err = 0; |
| 730 |
|
730 |
|
| 731 |
/* Search directory for matching names. */ |
731 |
/* Search directory for matching names. */ |
| 732 |
if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
732 |
if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC) |
| 733 |
readdirfunc = pglob->gl_readdir; |
733 |
readdirfunc = pglob->gl_readdir; |
| 734 |
else |
734 |
else |
| 735 |
readdirfunc = (struct dirent *(*)(void *))readdir; |
735 |
readdirfunc = (struct dirent *(*)(void *))readdir; |
|
Lines 737-748
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 737 |
u_char *sc; |
737 |
u_char *sc; |
| 738 |
Char *dc; |
738 |
Char *dc; |
| 739 |
|
739 |
|
| 740 |
if ((pglob->gl_flags & GLOB_LIMIT) && |
740 |
if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) && |
| 741 |
limitp->glim_readdir++ >= GLOB_LIMIT_READDIR) { |
741 |
limitp->glim_readdir++ >= COMPAT_GLOB_LIMIT_READDIR) { |
| 742 |
errno = 0; |
742 |
errno = 0; |
| 743 |
*pathend++ = SEP; |
743 |
*pathend++ = SEP; |
| 744 |
*pathend = EOS; |
744 |
*pathend = EOS; |
| 745 |
err = GLOB_NOSPACE; |
745 |
err = COMPAT_GLOB_NOSPACE; |
| 746 |
break; |
746 |
break; |
| 747 |
} |
747 |
} |
| 748 |
|
748 |
|
|
Lines 759-765
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 759 |
break; |
759 |
break; |
| 760 |
} |
760 |
} |
| 761 |
|
761 |
|
| 762 |
if (!match(pathend, pattern, restpattern, GLOB_LIMIT_RECUR)) { |
762 |
if (!match(pathend, pattern, restpattern, COMPAT_GLOB_LIMIT_RECUR)) { |
| 763 |
*pathend = EOS; |
763 |
*pathend = EOS; |
| 764 |
continue; |
764 |
continue; |
| 765 |
} |
765 |
} |
|
Lines 769-775
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 769 |
break; |
769 |
break; |
| 770 |
} |
770 |
} |
| 771 |
|
771 |
|
| 772 |
if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
772 |
if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC) |
| 773 |
(*pglob->gl_closedir)(dirp); |
773 |
(*pglob->gl_closedir)(dirp); |
| 774 |
else |
774 |
else |
| 775 |
closedir(dirp); |
775 |
closedir(dirp); |
|
Lines 792-798
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Link Here
|
| 792 |
* gl_pathv points to (gl_offs + gl_pathc + 1) items. |
792 |
* gl_pathv points to (gl_offs + gl_pathc + 1) items. |
| 793 |
*/ |
793 |
*/ |
| 794 |
static int |
794 |
static int |
| 795 |
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, |
795 |
globextend(const Char *path, compat_glob_t *pglob, struct glob_lim *limitp, |
| 796 |
struct stat *sb) |
796 |
struct stat *sb) |
| 797 |
{ |
797 |
{ |
| 798 |
char **pathv; |
798 |
char **pathv; |
|
Lines 812-818
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
Link Here
|
| 812 |
for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { |
812 |
for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { |
| 813 |
if (pglob->gl_pathv && pglob->gl_pathv[i]) |
813 |
if (pglob->gl_pathv && pglob->gl_pathv[i]) |
| 814 |
free(pglob->gl_pathv[i]); |
814 |
free(pglob->gl_pathv[i]); |
| 815 |
if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && |
815 |
if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT) != 0 && |
| 816 |
pglob->gl_pathv && pglob->gl_pathv[i]) |
816 |
pglob->gl_pathv && pglob->gl_pathv[i]) |
| 817 |
free(pglob->gl_statv[i]); |
817 |
free(pglob->gl_statv[i]); |
| 818 |
} |
818 |
} |
|
Lines 824-830
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
Link Here
|
| 824 |
free(pglob->gl_statv); |
824 |
free(pglob->gl_statv); |
| 825 |
pglob->gl_statv = NULL; |
825 |
pglob->gl_statv = NULL; |
| 826 |
} |
826 |
} |
| 827 |
return(GLOB_NOSPACE); |
827 |
return(COMPAT_GLOB_NOSPACE); |
| 828 |
} |
828 |
} |
| 829 |
|
829 |
|
| 830 |
pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv)); |
830 |
pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv)); |
|
Lines 838-844
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
Link Here
|
| 838 |
} |
838 |
} |
| 839 |
pglob->gl_pathv = pathv; |
839 |
pglob->gl_pathv = pathv; |
| 840 |
|
840 |
|
| 841 |
if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) { |
841 |
if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT) != 0) { |
| 842 |
statv = realloc(pglob->gl_statv, newn * sizeof(*statv)); |
842 |
statv = realloc(pglob->gl_statv, newn * sizeof(*statv)); |
| 843 |
if (statv == NULL) |
843 |
if (statv == NULL) |
| 844 |
goto nospace; |
844 |
goto nospace; |
|
Lines 853-862
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
Link Here
|
| 853 |
statv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
853 |
statv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
| 854 |
else { |
854 |
else { |
| 855 |
limitp->glim_malloc += sizeof(**statv); |
855 |
limitp->glim_malloc += sizeof(**statv); |
| 856 |
if ((pglob->gl_flags & GLOB_LIMIT) && |
856 |
if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) && |
| 857 |
limitp->glim_malloc >= GLOB_LIMIT_MALLOC) { |
857 |
limitp->glim_malloc >= COMPAT_GLOB_LIMIT_MALLOC) { |
| 858 |
errno = 0; |
858 |
errno = 0; |
| 859 |
return(GLOB_NOSPACE); |
859 |
return(COMPAT_GLOB_NOSPACE); |
| 860 |
} |
860 |
} |
| 861 |
if ((statv[pglob->gl_offs + pglob->gl_pathc] = |
861 |
if ((statv[pglob->gl_offs + pglob->gl_pathc] = |
| 862 |
malloc(sizeof(**statv))) == NULL) |
862 |
malloc(sizeof(**statv))) == NULL) |
|
Lines 874-893
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
Link Here
|
| 874 |
if ((copy = malloc(len)) != NULL) { |
874 |
if ((copy = malloc(len)) != NULL) { |
| 875 |
if (g_Ctoc(path, copy, len)) { |
875 |
if (g_Ctoc(path, copy, len)) { |
| 876 |
free(copy); |
876 |
free(copy); |
| 877 |
return(GLOB_NOSPACE); |
877 |
return(COMPAT_GLOB_NOSPACE); |
| 878 |
} |
878 |
} |
| 879 |
pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; |
879 |
pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; |
| 880 |
} |
880 |
} |
| 881 |
pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
881 |
pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
| 882 |
|
882 |
|
| 883 |
if ((pglob->gl_flags & GLOB_LIMIT) && |
883 |
if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) && |
| 884 |
(newn * sizeof(*pathv)) + limitp->glim_malloc > |
884 |
(newn * sizeof(*pathv)) + limitp->glim_malloc > |
| 885 |
GLOB_LIMIT_MALLOC) { |
885 |
COMPAT_GLOB_LIMIT_MALLOC) { |
| 886 |
errno = 0; |
886 |
errno = 0; |
| 887 |
return(GLOB_NOSPACE); |
887 |
return(COMPAT_GLOB_NOSPACE); |
| 888 |
} |
888 |
} |
| 889 |
copy_error: |
889 |
copy_error: |
| 890 |
return(copy == NULL ? GLOB_NOSPACE : 0); |
890 |
return(copy == NULL ? COMPAT_GLOB_NOSPACE : 0); |
| 891 |
} |
891 |
} |
| 892 |
|
892 |
|
| 893 |
|
893 |
|
|
Lines 902-908
match(Char *name, Char *pat, Char *patend, int recur)
Link Here
|
| 902 |
Char c, k; |
902 |
Char c, k; |
| 903 |
|
903 |
|
| 904 |
if (recur-- == 0) |
904 |
if (recur-- == 0) |
| 905 |
return(GLOB_NOSPACE); |
905 |
return(COMPAT_GLOB_NOSPACE); |
| 906 |
|
906 |
|
| 907 |
while (pat < patend) { |
907 |
while (pat < patend) { |
| 908 |
c = *pat++; |
908 |
c = *pat++; |
|
Lines 956-962
match(Char *name, Char *pat, Char *patend, int recur)
Link Here
|
| 956 |
|
956 |
|
| 957 |
/* Free allocated data belonging to a glob_t structure. */ |
957 |
/* Free allocated data belonging to a glob_t structure. */ |
| 958 |
void |
958 |
void |
| 959 |
globfree(glob_t *pglob) |
959 |
compat_globfree(compat_glob_t *pglob) |
| 960 |
{ |
960 |
{ |
| 961 |
int i; |
961 |
int i; |
| 962 |
char **pp; |
962 |
char **pp; |
|
Lines 980-986
globfree(glob_t *pglob)
Link Here
|
| 980 |
} |
980 |
} |
| 981 |
|
981 |
|
| 982 |
static DIR * |
982 |
static DIR * |
| 983 |
g_opendir(Char *str, glob_t *pglob) |
983 |
g_opendir(Char *str, compat_glob_t *pglob) |
| 984 |
{ |
984 |
{ |
| 985 |
char buf[MAXPATHLEN]; |
985 |
char buf[MAXPATHLEN]; |
| 986 |
|
986 |
|
|
Lines 991-1022
g_opendir(Char *str, glob_t *pglob)
Link Here
|
| 991 |
return(NULL); |
991 |
return(NULL); |
| 992 |
} |
992 |
} |
| 993 |
|
993 |
|
| 994 |
if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
994 |
if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC) |
| 995 |
return((*pglob->gl_opendir)(buf)); |
995 |
return((*pglob->gl_opendir)(buf)); |
| 996 |
|
996 |
|
| 997 |
return(opendir(buf)); |
997 |
return(opendir(buf)); |
| 998 |
} |
998 |
} |
| 999 |
|
999 |
|
| 1000 |
static int |
1000 |
static int |
| 1001 |
g_lstat(Char *fn, struct stat *sb, glob_t *pglob) |
1001 |
g_lstat(Char *fn, struct stat *sb, compat_glob_t *pglob) |
| 1002 |
{ |
1002 |
{ |
| 1003 |
char buf[MAXPATHLEN]; |
1003 |
char buf[MAXPATHLEN]; |
| 1004 |
|
1004 |
|
| 1005 |
if (g_Ctoc(fn, buf, sizeof(buf))) |
1005 |
if (g_Ctoc(fn, buf, sizeof(buf))) |
| 1006 |
return(-1); |
1006 |
return(-1); |
| 1007 |
if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
1007 |
if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC) |
| 1008 |
return((*pglob->gl_lstat)(buf, sb)); |
1008 |
return((*pglob->gl_lstat)(buf, sb)); |
| 1009 |
return(lstat(buf, sb)); |
1009 |
return(lstat(buf, sb)); |
| 1010 |
} |
1010 |
} |
| 1011 |
|
1011 |
|
| 1012 |
static int |
1012 |
static int |
| 1013 |
g_stat(Char *fn, struct stat *sb, glob_t *pglob) |
1013 |
g_stat(Char *fn, struct stat *sb, compat_glob_t *pglob) |
| 1014 |
{ |
1014 |
{ |
| 1015 |
char buf[MAXPATHLEN]; |
1015 |
char buf[MAXPATHLEN]; |
| 1016 |
|
1016 |
|
| 1017 |
if (g_Ctoc(fn, buf, sizeof(buf))) |
1017 |
if (g_Ctoc(fn, buf, sizeof(buf))) |
| 1018 |
return(-1); |
1018 |
return(-1); |
| 1019 |
if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
1019 |
if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC) |
| 1020 |
return((*pglob->gl_stat)(buf, sb)); |
1020 |
return((*pglob->gl_stat)(buf, sb)); |
| 1021 |
return(stat(buf, sb)); |
1021 |
return(stat(buf, sb)); |
| 1022 |
} |
1022 |
} |