]> andersk Git - openssh.git/blobdiff - openbsd-compat/glob.c
- markus@cvs.openbsd.org 2002/06/08 05:07:56
[openssh.git] / openbsd-compat / glob.c
index 677a8a10c076288b8c647008b0087fd467e48541..365d4334fc5d6ced0024b242a0042f83bc6bd7b8 100644 (file)
@@ -37,8 +37,8 @@
 #include "includes.h"
 #include <ctype.h>
 
-long
-get_arg_max()
+static long
+get_arg_max(void)
 {
 #ifdef ARG_MAX
        return(ARG_MAX);
@@ -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
This page took 0.046612 seconds and 4 git commands to generate.