#include "includes.h"
#include <ctype.h>
-long
-get_arg_max()
+static long
+get_arg_max(void)
{
#ifdef ARG_MAX
return(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 */
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));
--patnext;
}
*bufnext++ = c | M_PROTECT;
- }
- else
+ } else
*bufnext++ = c;
}
*bufnext = EOS;
/* copy part up to the brace */
for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
- continue;
+ ;
*lm = EOS;
ls = lm;
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.
*/
pe = pm;
}
- }
- else if (*pe == LBRACE)
+ } else if (*pe == LBRACE)
i++;
else if (*pe == RBRACE) {
if (i == 0)
case LBRACKET:
/* Ignore everything between [] */
for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
- continue;
+ ;
if (*pm == EOS) {
/*
* We could not find a matching RBRACKET.
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
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
else
h = pwd->pw_dir;
}
- }
- else {
+ } else {
/*
* Expand a ~user
*/
/* 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;
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)
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);
}
if (!*str)
strcpy(buf, ".");
else {
- if (g_Ctoc(str, buf, buf+sizeof(buf)))
+ if (g_Ctoc(str, buf, sizeof(buf)))
return(NULL);
}
{
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));
{
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));
}
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