summaryrefslogtreecommitdiff
path: root/openbsd-compat/glob.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/glob.c')
-rw-r--r--openbsd-compat/glob.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c
index 677a8a10c..4f70149cb 100644
--- a/openbsd-compat/glob.c
+++ b/openbsd-compat/glob.c
@@ -56,7 +56,7 @@ get_arg_max()
56#if 0 56#if 0
57static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; 57static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
58#else 58#else
59static char rcsid[] = "$OpenBSD: glob.c,v 1.14 2001/03/28 20:54:19 millert Exp $"; 59static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $";
60#endif 60#endif
61#endif /* LIBC_SCCS and not lint */ 61#endif /* LIBC_SCCS and not lint */
62 62
@@ -137,7 +137,7 @@ typedef char Char;
137 137
138 138
139static int compare __P((const void *, const void *)); 139static int compare __P((const void *, const void *));
140static int g_Ctoc __P((const Char *, char *, char *)); 140static int g_Ctoc __P((const Char *, char *, u_int));
141static int g_lstat __P((Char *, struct stat *, glob_t *)); 141static int g_lstat __P((Char *, struct stat *, glob_t *));
142static DIR *g_opendir __P((Char *, glob_t *)); 142static DIR *g_opendir __P((Char *, glob_t *));
143static Char *g_strchr __P((Char *, int)); 143static Char *g_strchr __P((Char *, int));
@@ -193,8 +193,7 @@ glob(pattern, flags, errfunc, pglob)
193 --patnext; 193 --patnext;
194 } 194 }
195 *bufnext++ = c | M_PROTECT; 195 *bufnext++ = c | M_PROTECT;
196 } 196 } else
197 else
198 *bufnext++ = c; 197 *bufnext++ = c;
199 } 198 }
200 *bufnext = EOS; 199 *bufnext = EOS;
@@ -248,7 +247,7 @@ globexp2(ptr, pattern, pglob, rv)
248 247
249 /* copy part up to the brace */ 248 /* copy part up to the brace */
250 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) 249 for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
251 continue; 250 ;
252 *lm = EOS; 251 *lm = EOS;
253 ls = lm; 252 ls = lm;
254 253
@@ -257,7 +256,7 @@ globexp2(ptr, pattern, pglob, rv)
257 if (*pe == LBRACKET) { 256 if (*pe == LBRACKET) {
258 /* Ignore everything between [] */ 257 /* Ignore everything between [] */
259 for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) 258 for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
260 continue; 259 ;
261 if (*pe == EOS) { 260 if (*pe == EOS) {
262 /* 261 /*
263 * We could not find a matching RBRACKET. 262 * We could not find a matching RBRACKET.
@@ -265,8 +264,7 @@ globexp2(ptr, pattern, pglob, rv)
265 */ 264 */
266 pe = pm; 265 pe = pm;
267 } 266 }
268 } 267 } else if (*pe == LBRACE)
269 else if (*pe == LBRACE)
270 i++; 268 i++;
271 else if (*pe == RBRACE) { 269 else if (*pe == RBRACE) {
272 if (i == 0) 270 if (i == 0)
@@ -285,7 +283,7 @@ globexp2(ptr, pattern, pglob, rv)
285 case LBRACKET: 283 case LBRACKET:
286 /* Ignore everything between [] */ 284 /* Ignore everything between [] */
287 for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) 285 for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
288 continue; 286 ;
289 if (*pm == EOS) { 287 if (*pm == EOS) {
290 /* 288 /*
291 * We could not find a matching RBRACKET. 289 * We could not find a matching RBRACKET.
@@ -311,13 +309,14 @@ globexp2(ptr, pattern, pglob, rv)
311 else { 309 else {
312 /* Append the current string */ 310 /* Append the current string */
313 for (lm = ls; (pl < pm); *lm++ = *pl++) 311 for (lm = ls; (pl < pm); *lm++ = *pl++)
314 continue; 312 ;
313
315 /* 314 /*
316 * Append the rest of the pattern after the 315 * Append the rest of the pattern after the
317 * closing brace 316 * closing brace
318 */ 317 */
319 for (pl = pe + 1; (*lm++ = *pl++) != EOS;) 318 for (pl = pe + 1; (*lm++ = *pl++) != EOS; )
320 continue; 319 ;
321 320
322 /* Expand the current pattern */ 321 /* Expand the current pattern */
323#ifdef DEBUG 322#ifdef DEBUG
@@ -362,10 +361,15 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
362 eb = &patbuf[patbuf_len - 1]; 361 eb = &patbuf[patbuf_len - 1];
363 for (p = pattern + 1, h = (char *) patbuf; 362 for (p = pattern + 1, h = (char *) patbuf;
364 h < (char *)eb && *p && *p != SLASH; *h++ = *p++) 363 h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
365 continue; 364 ;
366 365
367 *h = EOS; 366 *h = EOS;
368 367
368#if 0
369 if (h == (char *)eb)
370 return what;
371#endif
372
369 if (((char *) patbuf)[0] == EOS) { 373 if (((char *) patbuf)[0] == EOS) {
370 /* 374 /*
371 * handle a plain ~ or ~/ by expanding $HOME 375 * handle a plain ~ or ~/ by expanding $HOME
@@ -380,8 +384,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
380 else 384 else
381 h = pwd->pw_dir; 385 h = pwd->pw_dir;
382 } 386 }
383 } 387 } else {
384 else {
385 /* 388 /*
386 * Expand a ~user 389 * Expand a ~user
387 */ 390 */
@@ -393,11 +396,11 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
393 396
394 /* Copy the home directory */ 397 /* Copy the home directory */
395 for (b = patbuf; b < eb && *h; *b++ = *h++) 398 for (b = patbuf; b < eb && *h; *b++ = *h++)
396 continue; 399 ;
397 400
398 /* Append the rest of the pattern */ 401 /* Append the rest of the pattern */
399 while (b < eb && (*b++ = *p++) != EOS) 402 while (b < eb && (*b++ = *p++) != EOS)
400 continue; 403 ;
401 *b = EOS; 404 *b = EOS;
402 405
403 return patbuf; 406 return patbuf;
@@ -621,7 +624,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
621 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { 624 if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
622 /* TODO: don't call for ENOENT or ENOTDIR? */ 625 /* TODO: don't call for ENOENT or ENOTDIR? */
623 if (pglob->gl_errfunc) { 626 if (pglob->gl_errfunc) {
624 if (g_Ctoc(pathbuf, buf, buf+sizeof(buf))) 627 if (g_Ctoc(pathbuf, buf, sizeof(buf)))
625 return(GLOB_ABORTED); 628 return(GLOB_ABORTED);
626 if (pglob->gl_errfunc(buf, errno) || 629 if (pglob->gl_errfunc(buf, errno) ||
627 pglob->gl_flags & GLOB_ERR) 630 pglob->gl_flags & GLOB_ERR)
@@ -718,11 +721,11 @@ globextend(path, pglob, limitp)
718 pglob->gl_pathv = pathv; 721 pglob->gl_pathv = pathv;
719 722
720 for (p = path; *p++;) 723 for (p = path; *p++;)
721 continue; 724 ;
722 len = (size_t)(p - path); 725 len = (size_t)(p - path);
723 *limitp += len; 726 *limitp += len;
724 if ((copy = malloc(len)) != NULL) { 727 if ((copy = malloc(len)) != NULL) {
725 if (g_Ctoc(path, copy, copy+len+1)) { 728 if (g_Ctoc(path, copy, len)) {
726 free(copy); 729 free(copy);
727 return(GLOB_NOSPACE); 730 return(GLOB_NOSPACE);
728 } 731 }
@@ -820,7 +823,7 @@ g_opendir(str, pglob)
820 if (!*str) 823 if (!*str)
821 strcpy(buf, "."); 824 strcpy(buf, ".");
822 else { 825 else {
823 if (g_Ctoc(str, buf, buf+sizeof(buf))) 826 if (g_Ctoc(str, buf, sizeof(buf)))
824 return(NULL); 827 return(NULL);
825 } 828 }
826 829
@@ -838,7 +841,7 @@ g_lstat(fn, sb, pglob)
838{ 841{
839 char buf[MAXPATHLEN]; 842 char buf[MAXPATHLEN];
840 843
841 if (g_Ctoc(fn, buf, buf+sizeof(buf))) 844 if (g_Ctoc(fn, buf, sizeof(buf)))
842 return(-1); 845 return(-1);
843 if (pglob->gl_flags & GLOB_ALTDIRFUNC) 846 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
844 return((*pglob->gl_lstat)(buf, sb)); 847 return((*pglob->gl_lstat)(buf, sb));
@@ -853,7 +856,7 @@ g_stat(fn, sb, pglob)
853{ 856{
854 char buf[MAXPATHLEN]; 857 char buf[MAXPATHLEN];
855 858
856 if (g_Ctoc(fn, buf, buf+sizeof(buf))) 859 if (g_Ctoc(fn, buf, sizeof(buf)))
857 return(-1); 860 return(-1);
858 if (pglob->gl_flags & GLOB_ALTDIRFUNC) 861 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
859 return((*pglob->gl_stat)(buf, sb)); 862 return((*pglob->gl_stat)(buf, sb));
@@ -873,17 +876,17 @@ g_strchr(str, ch)
873} 876}
874 877
875static int 878static int
876g_Ctoc(str, buf, ebuf) 879g_Ctoc(str, buf, len)
877 register const Char *str; 880 register const Char *str;
878 char *buf, *ebuf; 881 char *buf;
882 u_int len;
879{ 883{
880 register char *dc;
881 884
882 for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;) 885 while (len--) {
883 continue; 886 if ((*buf++ = *str++) == EOS)
884 if (dc >= ebuf) 887 return (0);
885 return (1); 888 }
886 return (0); 889 return (1);
887} 890}
888 891
889#ifdef DEBUG 892#ifdef DEBUG