]> andersk Git - openssh.git/blobdiff - openbsd-compat/glob.c
- djm@cvs.openbsd.org 2010/01/30 02:54:53
[openssh.git] / openbsd-compat / glob.c
index b42cedb79edb554c7c7bdf3f0881fdd009301ea8..74b506403ec87eb533a4182bc90ade1a57f98067 100644 (file)
@@ -1,3 +1,4 @@
+/*     $OpenBSD: glob.c,v 1.26 2005/11/28 17:50:12 deraadt Exp $ */
 /*
  * Copyright (c) 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
  * SUCH DAMAGE.
  */
 
+/* OPENBSD ORIGINAL: lib/libc/gen/glob.c */
+
 #include "includes.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <dirent.h>
 #include <ctype.h>
+#include <errno.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \
-    !defined(GLOB_HAS_GL_MATCHC)
+    !defined(GLOB_HAS_GL_MATCHC) || \
+    !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \
+    defined(BROKEN_GLOB)
 
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)glob.c     8.3 (Berkeley) 10/13/93";
+static long
+get_arg_max(void)
+{
+#ifdef ARG_MAX
+       return(ARG_MAX);
+#elif defined(HAVE_SYSCONF) && defined(_SC_ARG_MAX)
+       return(sysconf(_SC_ARG_MAX));
 #else
-static char rcsid[] = "$OpenBSD: glob.c,v 1.9 2001/03/18 17:18:58 deraadt Exp $";
+       return(256); /* XXX: arbitrary */
 #endif
-#endif /* LIBC_SCCS and not lint */
+}
 
 /*
  * glob(3) -- a superset of the one defined in POSIX 1003.2.
@@ -85,6 +100,7 @@ static char rcsid[] = "$OpenBSD: glob.c,v 1.9 2001/03/18 17:18:58 deraadt Exp $"
 #define        RBRACKET        ']'
 #define        SEP             '/'
 #define        STAR            '*'
+#undef TILDE                   /* Some platforms may already define it */
 #define        TILDE           '~'
 #define        UNDERSCORE      '_'
 #define        LBRACE          '{'
@@ -124,39 +140,35 @@ typedef char Char;
 #define        ismeta(c)       (((c)&M_QUOTE) != 0)
 
 
-static int      compare __P((const void *, const void *));
-static void     g_Ctoc __P((const Char *, char *));
-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));
-#ifdef notdef
-static Char    *g_strcat __P((Char *, const Char *));
-#endif
-static int      g_stat __P((Char *, struct stat *, glob_t *));
-static int      glob0 __P((const Char *, glob_t *));
-static int      glob1 __P((Char *, glob_t *, size_t *));
-static int      glob2 __P((Char *, Char *, Char *, glob_t *, size_t *));
-static int      glob3 __P((Char *, Char *, Char *, Char *, glob_t *,
-                   size_t *));
-static int      globextend __P((const Char *, glob_t *, size_t *));
+static int      compare(const void *, const void *);
+static int      g_Ctoc(const Char *, char *, u_int);
+static int      g_lstat(Char *, struct stat *, glob_t *);
+static DIR     *g_opendir(Char *, glob_t *);
+static Char    *g_strchr(Char *, int);
+static int      g_stat(Char *, struct stat *, glob_t *);
+static int      glob0(const Char *, glob_t *);
+static int      glob1(Char *, Char *, glob_t *, size_t *);
+static int      glob2(Char *, Char *, Char *, Char *, Char *, Char *,
+                   glob_t *, size_t *);
+static int      glob3(Char *, Char *, Char *, Char *, Char *,
+                   Char *, Char *, glob_t *, size_t *);
+static int      globextend(const Char *, glob_t *, size_t *);
 static const Char *
-                globtilde __P((const Char *, Char *, size_t, glob_t *));
-static int      globexp1 __P((const Char *, glob_t *));
-static int      globexp2 __P((const Char *, const Char *, glob_t *, int *));
-static int      match __P((Char *, Char *, Char *));
+                globtilde(const Char *, Char *, size_t, glob_t *);
+static int      globexp1(const Char *, glob_t *);
+static int      globexp2(const Char *, const Char *, glob_t *, int *);
+static int      match(Char *, Char *, Char *);
 #ifdef DEBUG
-static void     qprintf __P((const char *, Char *));
+static void     qprintf(const char *, Char *);
 #endif
 
 int
-glob(pattern, flags, errfunc, pglob)
-       const char *pattern;
-       int flags, (*errfunc) __P((const char *, int));
-       glob_t *pglob;
+glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
+    glob_t *pglob)
 {
        const u_char *patnext;
        int c;
-       Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
+       Char *bufnext, *bufend, patbuf[MAXPATHLEN];
 
        patnext = (u_char *) pattern;
        if (!(flags & GLOB_APPEND)) {
@@ -170,10 +182,10 @@ glob(pattern, flags, errfunc, pglob)
        pglob->gl_matchc = 0;
 
        bufnext = patbuf;
-       bufend = bufnext + MAXPATHLEN;
+       bufend = bufnext + MAXPATHLEN - 1;
        if (flags & GLOB_NOESCAPE)
-           while (bufnext < bufend && (c = *patnext++) != EOS)
-                   *bufnext++ = c;
+               while (bufnext < bufend && (c = *patnext++) != EOS)
+                       *bufnext++ = c;
        else {
                /* Protect the quoted characters. */
                while (bufnext < bufend && (c = *patnext++) != EOS)
@@ -183,8 +195,7 @@ glob(pattern, flags, errfunc, pglob)
                                        --patnext;
                                }
                                *bufnext++ = c | M_PROTECT;
-                       }
-                       else
+                       } else
                                *bufnext++ = c;
        }
        *bufnext = EOS;
@@ -200,9 +211,8 @@ glob(pattern, flags, errfunc, pglob)
  * invoke the standard globbing routine to glob the rest of the magic
  * characters
  */
-static int globexp1(pattern, pglob)
-       const Char *pattern;
-       glob_t *pglob;
+static int
+globexp1(const Char *pattern, glob_t *pglob)
 {
        const Char* ptr = pattern;
        int rv;
@@ -224,19 +234,18 @@ static int globexp1(pattern, pglob)
  * If it succeeds then it invokes globexp1 with the new pattern.
  * If it fails then it tries to glob the rest of the pattern and returns.
  */
-static int globexp2(ptr, pattern, pglob, rv)
-       const Char *ptr, *pattern;
-       glob_t *pglob;
-       int *rv;
+static int
+globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
 {
        int     i;
        Char   *lm, *ls;
        const Char *pe, *pm, *pl;
-       Char    patbuf[MAXPATHLEN + 1];
+       Char    patbuf[MAXPATHLEN];
 
        /* copy part up to the brace */
        for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
-               continue;
+               ;
+       *lm = EOS;
        ls = lm;
 
        /* Find the balanced brace */
@@ -244,7 +253,7 @@ static int 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.
@@ -252,8 +261,7 @@ static int globexp2(ptr, pattern, pglob, rv)
                                 */
                                pe = pm;
                        }
-               }
-               else if (*pe == LBRACE)
+               } else if (*pe == LBRACE)
                        i++;
                else if (*pe == RBRACE) {
                        if (i == 0)
@@ -267,12 +275,12 @@ static int globexp2(ptr, pattern, pglob, rv)
                return 0;
        }
 
-       for (i = 0, pl = pm = ptr; pm <= pe; pm++)
+       for (i = 0, pl = pm = ptr; pm <= pe; pm++) {
                switch (*pm) {
                case LBRACKET:
                        /* Ignore everything between [] */
                        for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
-                               continue;
+                               ;
                        if (*pm == EOS) {
                                /*
                                 * We could not find a matching RBRACKET.
@@ -288,8 +296,8 @@ static int globexp2(ptr, pattern, pglob, rv)
 
                case RBRACE:
                        if (i) {
-                           i--;
-                           break;
+                               i--;
+                               break;
                        }
                        /* FALLTHROUGH */
                case COMMA:
@@ -298,13 +306,14 @@ static int 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
@@ -320,6 +329,7 @@ static int globexp2(ptr, pattern, pglob, rv)
                default:
                        break;
                }
+       }
        *rv = 0;
        return 0;
 }
@@ -330,11 +340,7 @@ static int globexp2(ptr, pattern, pglob, rv)
  * expand tilde from the passwd file.
  */
 static const Char *
-globtilde(pattern, patbuf, patbuf_len, pglob)
-       const Char *pattern;
-       Char *patbuf;
-       size_t patbuf_len;
-       glob_t *pglob;
+globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
 {
        struct passwd *pwd;
        char *h;
@@ -348,10 +354,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
@@ -366,8 +377,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
                        else
                                h = pwd->pw_dir;
                }
-       }
-       else {
+       } else {
                /*
                 * Expand a ~user
                 */
@@ -379,11 +389,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;
@@ -398,17 +408,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
  * to find no matches.
  */
 static int
-glob0(pattern, pglob)
-       const Char *pattern;
-       glob_t *pglob;
+glob0(const Char *pattern, glob_t *pglob)
 {
        const Char *qpatnext;
        int c, err, oldpathc;
-       Char *bufnext, patbuf[MAXPATHLEN+1];
+       Char *bufnext, patbuf[MAXPATHLEN];
        size_t limit = 0;
 
-       qpatnext = globtilde(pattern, patbuf, sizeof(patbuf) / sizeof(Char),
-           pglob);
+       qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
        oldpathc = pglob->gl_pathc;
        bufnext = patbuf;
 
@@ -452,7 +459,7 @@ glob0(pattern, pglob)
                         * to avoid exponential behavior
                         */
                        if (bufnext == patbuf || bufnext[-1] != M_ALL)
-                           *bufnext++ = M_ALL;
+                               *bufnext++ = M_ALL;
                        break;
                default:
                        *bufnext++ = CHAR(c);
@@ -464,7 +471,7 @@ glob0(pattern, pglob)
        qprintf("glob0:", patbuf);
 #endif
 
-       if ((err = glob1(patbuf, pglob, &limit)) != 0)
+       if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0)
                return(err);
 
        /*
@@ -488,24 +495,22 @@ glob0(pattern, pglob)
 }
 
 static int
-compare(p, q)
-       const void *p, *q;
+compare(const void *p, const void *q)
 {
        return(strcmp(*(char **)p, *(char **)q));
 }
 
 static int
-glob1(pattern, pglob, limitp)
-       Char *pattern;
-       glob_t *pglob;
-       size_t *limitp;
+glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
 {
-       Char pathbuf[MAXPATHLEN+1];
+       Char pathbuf[MAXPATHLEN];
 
        /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
        if (*pattern == EOS)
                return(0);
-       return(glob2(pathbuf, pathbuf, pattern, pglob, limitp));
+       return(glob2(pathbuf, pathbuf+MAXPATHLEN-1,
+           pathbuf, pathbuf+MAXPATHLEN-1,
+           pattern, pattern_last, pglob, limitp));
 }
 
 /*
@@ -514,10 +519,8 @@ glob1(pattern, pglob, limitp)
  * meta characters.
  */
 static int
-glob2(pathbuf, pathend, pattern, pglob, limitp)
-       Char *pathbuf, *pathend, *pattern;
-       glob_t *pglob;
-       size_t *limitp;
+glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
+    Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
 {
        struct stat sb;
        Char *p, *q;
@@ -534,10 +537,12 @@ glob2(pathbuf, pathend, pattern, pglob, limitp)
                                return(0);
 
                        if (((pglob->gl_flags & GLOB_MARK) &&
-                           pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
-                           || (S_ISLNK(sb.st_mode) &&
+                           pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
+                           (S_ISLNK(sb.st_mode) &&
                            (g_stat(pathbuf, &sb, pglob) == 0) &&
                            S_ISDIR(sb.st_mode)))) {
+                               if (pathend+1 > pathend_last)
+                                       return (1);
                                *pathend++ = SEP;
                                *pathend = EOS;
                        }
@@ -551,28 +556,34 @@ glob2(pathbuf, pathend, pattern, pglob, limitp)
                while (*p != EOS && *p != SEP) {
                        if (ismeta(*p))
                                anymeta = 1;
+                       if (q+1 > pathend_last)
+                               return (1);
                        *q++ = *p++;
                }
 
                if (!anymeta) {         /* No expansion, do next segment. */
                        pathend = q;
                        pattern = p;
-                       while (*pattern == SEP)
+                       while (*pattern == SEP) {
+                               if (pathend+1 > pathend_last)
+                                       return (1);
                                *pathend++ = *pattern++;
-               } else                  /* Need expansion, recurse. */
-                       return(glob3(pathbuf, pathend, pattern, p, pglob,
-                           limitp));
+                       }
+               } else
+                       /* Need expansion, recurse. */
+                       return(glob3(pathbuf, pathbuf_last, pathend,
+                           pathend_last, pattern, p, pattern_last,
+                           pglob, limitp));
        }
        /* NOTREACHED */
 }
 
 static int
-glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp)
-       Char *pathbuf, *pathend, *pattern, *restpattern;
-       glob_t *pglob;
-       size_t *limitp;
+glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
+    Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob,
+    size_t *limitp)
 {
-       register struct dirent *dp;
+       struct dirent *dp;
        DIR *dirp;
        int err;
        char buf[MAXPATHLEN];
@@ -583,18 +594,21 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp)
         * and dirent.h as taking pointers to differently typed opaque
         * structures.
         */
-       struct dirent *(*readdirfunc)();
+       struct dirent *(*readdirfunc)(void *);
 
+       if (pathend > pathend_last)
+               return (1);
        *pathend = EOS;
        errno = 0;
 
        if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
                /* TODO: don't call for ENOENT or ENOTDIR? */
                if (pglob->gl_errfunc) {
-                       g_Ctoc(pathbuf, buf);
+                       if (g_Ctoc(pathbuf, buf, sizeof(buf)))
+                               return(GLOB_ABORTED);
                        if (pglob->gl_errfunc(buf, errno) ||
                            pglob->gl_flags & GLOB_ERR)
-                               return (GLOB_ABORTED);
+                               return(GLOB_ABORTED);
                }
                return(0);
        }
@@ -605,22 +619,30 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp)
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                readdirfunc = pglob->gl_readdir;
        else
-               readdirfunc = readdir;
+               readdirfunc = (struct dirent *(*)(void *))readdir;
        while ((dp = (*readdirfunc)(dirp))) {
-               register u_char *sc;
-               register Char *dc;
+               u_char *sc;
+               Char *dc;
 
                /* Initial DOT must be matched literally. */
                if (dp->d_name[0] == DOT && *pattern != DOT)
                        continue;
-               for (sc = (u_char *) dp->d_name, dc = pathend;
-                    (*dc++ = *sc++) != EOS;)
-                       continue;
+               dc = pathend;
+               sc = (u_char *) dp->d_name;
+               while (dc < pathend_last && (*dc++ = *sc++) != EOS)
+                       ;
+               if (dc >= pathend_last) {
+                       *dc = EOS;
+                       err = 1;
+                       break;
+               }
+
                if (!match(pathend, pattern, restpattern)) {
                        *pathend = EOS;
                        continue;
                }
-               err = glob2(pathbuf, --dc, restpattern, pglob, limitp);
+               err = glob2(pathbuf, pathbuf_last, --dc, pathend_last,
+                   restpattern, restpattern_last, pglob, limitp);
                if (err)
                        break;
        }
@@ -634,7 +656,7 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp)
 
 
 /*
- * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
+ * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
  * add the new item, and update gl_pathc.
  *
  * This assumes the BSD realloc, which only copies the block when its size
@@ -648,13 +670,10 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp)
  *     gl_pathv points to (gl_offs + gl_pathc + 1) items.
  */
 static int
-globextend(path, pglob, limitp)
-       const Char *path;
-       glob_t *pglob;
-       size_t *limitp;
+globextend(const Char *path, glob_t *pglob, size_t *limitp)
 {
-       register char **pathv;
-       register int i;
+       char **pathv;
+       int i;
        u_int newsize, len;
        char *copy;
        const Char *p;
@@ -663,8 +682,10 @@ globextend(path, pglob, limitp)
        pathv = pglob->gl_pathv ? realloc((char *)pglob->gl_pathv, newsize) :
            malloc(newsize);
        if (pathv == NULL) {
-               if (pglob->gl_pathv)
+               if (pglob->gl_pathv) {
                        free(pglob->gl_pathv);
+                       pglob->gl_pathv = NULL;
+               }
                return(GLOB_NOSPACE);
        }
 
@@ -677,17 +698,20 @@ 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) {
-               g_Ctoc(path, copy);
+               if (g_Ctoc(path, copy, len)) {
+                       free(copy);
+                       return(GLOB_NOSPACE);
+               }
                pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
        }
        pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
 
        if ((pglob->gl_flags & GLOB_LIMIT) &&
-           newsize + *limitp >= ARG_MAX) {
+           newsize + *limitp >= (u_int) get_arg_max()) {
                errno = 0;
                return(GLOB_NOSPACE);
        }
@@ -701,8 +725,7 @@ globextend(path, pglob, limitp)
  * pattern causes a recursion level.
  */
 static int
-match(name, pat, patend)
-       register Char *name, *pat, *patend;
+match(Char *name, Char *pat, Char *patend)
 {
        int ok, negate_range;
        Char c, k;
@@ -713,10 +736,10 @@ match(name, pat, patend)
                case M_ALL:
                        if (pat == patend)
                                return(1);
-                       do
+                       do {
                            if (match(name, pat, patend))
                                    return(1);
-                       while (*name++ != EOS);
+                       while (*name++ != EOS);
                        return(0);
                case M_ONE:
                        if (*name++ == EOS)
@@ -749,11 +772,10 @@ match(name, pat, patend)
 
 /* Free allocated data belonging to a glob_t structure. */
 void
-globfree(pglob)
-       glob_t *pglob;
+globfree(glob_t *pglob)
 {
-       register int i;
-       register char **pp;
+       int i;
+       char **pp;
 
        if (pglob->gl_pathv != NULL) {
                pp = pglob->gl_pathv + pglob->gl_offs;
@@ -761,20 +783,21 @@ globfree(pglob)
                        if (*pp)
                                free(*pp);
                free(pglob->gl_pathv);
+               pglob->gl_pathv = NULL;
        }
 }
 
 static DIR *
-g_opendir(str, pglob)
-       register Char *str;
-       glob_t *pglob;
+g_opendir(Char *str, glob_t *pglob)
 {
        char buf[MAXPATHLEN];
 
        if (!*str)
-               strcpy(buf, ".");
-       else
-               g_Ctoc(str, buf);
+               strlcpy(buf, ".", sizeof buf);
+       else {
+               if (g_Ctoc(str, buf, sizeof(buf)))
+                       return(NULL);
+       }
 
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                return((*pglob->gl_opendir)(buf));
@@ -783,37 +806,31 @@ g_opendir(str, pglob)
 }
 
 static int
-g_lstat(fn, sb, pglob)
-       register Char *fn;
-       struct stat *sb;
-       glob_t *pglob;
+g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
 {
        char buf[MAXPATHLEN];
 
-       g_Ctoc(fn, buf);
+       if (g_Ctoc(fn, buf, sizeof(buf)))
+               return(-1);
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                return((*pglob->gl_lstat)(buf, sb));
        return(lstat(buf, sb));
 }
 
 static int
-g_stat(fn, sb, pglob)
-       register Char *fn;
-       struct stat *sb;
-       glob_t *pglob;
+g_stat(Char *fn, struct stat *sb, glob_t *pglob)
 {
        char buf[MAXPATHLEN];
 
-       g_Ctoc(fn, buf);
+       if (g_Ctoc(fn, buf, sizeof(buf)))
+               return(-1);
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                return((*pglob->gl_stat)(buf, sb));
        return(stat(buf, sb));
 }
 
 static Char *
-g_strchr(str, ch)
-       Char *str;
-       int ch;
+g_strchr(Char *str, int ch)
 {
        do {
                if (*str == ch)
@@ -822,42 +839,22 @@ g_strchr(str, ch)
        return (NULL);
 }
 
-#ifdef notdef
-static Char *
-g_strcat(dst, src)
-       Char *dst;
-       const Char* src;
-{
-       Char *sdst = dst;
-
-       while (*dst++)
-               continue;
-       --dst;
-       while((*dst++ = *src++) != EOS)
-               continue;
-
-       return (sdst);
-}
-#endif
-
-static void
-g_Ctoc(str, buf)
-       register const Char *str;
-       char *buf;
+static int
+g_Ctoc(const Char *str, char *buf, u_int len)
 {
-       register char *dc;
 
-       for (dc = buf; (*dc++ = *str++) != EOS;)
-               continue;
+       while (len--) {
+               if ((*buf++ = *str++) == EOS)
+                       return (0);
+       }
+       return (1);
 }
 
 #ifdef DEBUG
 static void
-qprintf(str, s)
-       const char *str;
-       register Char *s;
+qprintf(const char *str, Char *s)
 {
-       register Char *p;
+       Char *p;
 
        (void)printf("%s:\n", str);
        for (p = s; *p; p++)
This page took 0.101201 seconds and 4 git commands to generate.