diff options
author | Damien Miller <djm@mindrot.org> | 2001-04-14 00:22:33 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-04-14 00:22:33 +1000 |
commit | 6e77a538ca63f2ecbab74656839e77084a2db425 (patch) | |
tree | 03dd15234a4ccc802fba338e7b1e54e3a9e71b94 /openbsd-compat/glob.c | |
parent | 92d4a020011565d766153cbf85210157c33c541c (diff) |
- Sync with OpenBSD glob.c, strlcat.c and vis.c changes
Diffstat (limited to 'openbsd-compat/glob.c')
-rw-r--r-- | openbsd-compat/glob.c | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 677a8a10..4f70149c 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c @@ -56,7 +56,7 @@ get_arg_max() #if 0 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #else -static char rcsid[] = "$OpenBSD: glob.c,v 1.14 2001/03/28 20:54:19 millert Exp $"; +static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -137,7 +137,7 @@ typedef char Char; static int compare __P((const void *, const void *)); -static int g_Ctoc __P((const Char *, char *, char *)); +static int g_Ctoc __P((const Char *, char *, u_int)); static int g_lstat __P((Char *, struct stat *, glob_t *)); static DIR *g_opendir __P((Char *, glob_t *)); static Char *g_strchr __P((Char *, int)); @@ -193,8 +193,7 @@ glob(pattern, flags, errfunc, pglob) --patnext; } *bufnext++ = c | M_PROTECT; - } - else + } else *bufnext++ = c; } *bufnext = EOS; @@ -248,7 +247,7 @@ globexp2(ptr, pattern, pglob, rv) /* copy part up to the brace */ for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) - continue; + ; *lm = EOS; ls = lm; @@ -257,7 +256,7 @@ globexp2(ptr, pattern, pglob, rv) if (*pe == LBRACKET) { /* Ignore everything between [] */ for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) - continue; + ; if (*pe == EOS) { /* * We could not find a matching RBRACKET. @@ -265,8 +264,7 @@ globexp2(ptr, pattern, pglob, rv) */ pe = pm; } - } - else if (*pe == LBRACE) + } else if (*pe == LBRACE) i++; else if (*pe == RBRACE) { if (i == 0) @@ -285,7 +283,7 @@ globexp2(ptr, pattern, pglob, rv) case LBRACKET: /* Ignore everything between [] */ for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) - continue; + ; if (*pm == EOS) { /* * We could not find a matching RBRACKET. @@ -311,13 +309,14 @@ globexp2(ptr, pattern, pglob, rv) else { /* Append the current string */ for (lm = ls; (pl < pm); *lm++ = *pl++) - continue; + ; + /* * Append the rest of the pattern after the * closing brace */ - for (pl = pe + 1; (*lm++ = *pl++) != EOS;) - continue; + for (pl = pe + 1; (*lm++ = *pl++) != EOS; ) + ; /* Expand the current pattern */ #ifdef DEBUG @@ -362,10 +361,15 @@ globtilde(pattern, patbuf, patbuf_len, pglob) eb = &patbuf[patbuf_len - 1]; for (p = pattern + 1, h = (char *) patbuf; h < (char *)eb && *p && *p != SLASH; *h++ = *p++) - continue; + ; *h = EOS; +#if 0 + if (h == (char *)eb) + return what; +#endif + if (((char *) patbuf)[0] == EOS) { /* * handle a plain ~ or ~/ by expanding $HOME @@ -380,8 +384,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob) else h = pwd->pw_dir; } - } - else { + } else { /* * Expand a ~user */ @@ -393,11 +396,11 @@ globtilde(pattern, patbuf, patbuf_len, pglob) /* Copy the home directory */ for (b = patbuf; b < eb && *h; *b++ = *h++) - continue; + ; /* Append the rest of the pattern */ while (b < eb && (*b++ = *p++) != EOS) - continue; + ; *b = EOS; return patbuf; @@ -621,7 +624,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { /* TODO: don't call for ENOENT or ENOTDIR? */ if (pglob->gl_errfunc) { - if (g_Ctoc(pathbuf, buf, buf+sizeof(buf))) + if (g_Ctoc(pathbuf, buf, sizeof(buf))) return(GLOB_ABORTED); if (pglob->gl_errfunc(buf, errno) || pglob->gl_flags & GLOB_ERR) @@ -718,11 +721,11 @@ globextend(path, pglob, limitp) pglob->gl_pathv = pathv; for (p = path; *p++;) - continue; + ; len = (size_t)(p - path); *limitp += len; if ((copy = malloc(len)) != NULL) { - if (g_Ctoc(path, copy, copy+len+1)) { + if (g_Ctoc(path, copy, len)) { free(copy); return(GLOB_NOSPACE); } @@ -820,7 +823,7 @@ g_opendir(str, pglob) if (!*str) strcpy(buf, "."); else { - if (g_Ctoc(str, buf, buf+sizeof(buf))) + if (g_Ctoc(str, buf, sizeof(buf))) return(NULL); } @@ -838,7 +841,7 @@ g_lstat(fn, sb, pglob) { char buf[MAXPATHLEN]; - if (g_Ctoc(fn, buf, buf+sizeof(buf))) + if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_lstat)(buf, sb)); @@ -853,7 +856,7 @@ g_stat(fn, sb, pglob) { char buf[MAXPATHLEN]; - if (g_Ctoc(fn, buf, buf+sizeof(buf))) + if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_stat)(buf, sb)); @@ -873,17 +876,17 @@ g_strchr(str, ch) } static int -g_Ctoc(str, buf, ebuf) +g_Ctoc(str, buf, len) register const Char *str; - char *buf, *ebuf; + char *buf; + u_int len; { - register char *dc; - for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;) - continue; - if (dc >= ebuf) - return (1); - return (0); + while (len--) { + if ((*buf++ = *str++) == EOS) + return (0); + } + return (1); } #ifdef DEBUG |