]> 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 7fafc8c402876680a60607d9f1479f8530f51597..74b506403ec87eb533a4182bc90ade1a57f98067 100644 (file)
@@ -1,5 +1,4 @@
-/* OPENBSD ORIGINAL: lib/libc/gen/glob.c */
-
+/*     $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.
  * 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(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \
+    defined(BROKEN_GLOB)
 
 static long
 get_arg_max(void)
@@ -47,17 +63,6 @@ get_arg_max(void)
 #endif
 }
 
-#if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \
-    !defined(GLOB_HAS_GL_MATCHC)
-
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)glob.c     8.3 (Berkeley) 10/13/93";
-#else
-static char rcsid[] = "$OpenBSD: glob.c,v 1.22 2003/06/25 21:16:47 deraadt Exp $";
-#endif
-#endif /* LIBC_SCCS and not lint */
-
 /*
  * glob(3) -- a superset of the one defined in POSIX 1003.2.
  *
@@ -145,7 +150,7 @@ 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 *,
+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 *
@@ -158,10 +163,8 @@ static void         qprintf(const char *, Char *);
 #endif
 
 int
-glob(pattern, flags, errfunc, pglob)
-       const char *pattern;
-       int flags, (*errfunc)(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;
@@ -209,9 +212,7 @@ glob(pattern, flags, errfunc, pglob)
  * characters
  */
 static int
-globexp1(pattern, pglob)
-       const Char *pattern;
-       glob_t *pglob;
+globexp1(const Char *pattern, glob_t *pglob)
 {
        const Char* ptr = pattern;
        int rv;
@@ -234,10 +235,7 @@ globexp1(pattern, pglob)
  * 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;
+globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
 {
        int     i;
        Char   *lm, *ls;
@@ -342,11 +340,7 @@ 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;
@@ -414,9 +408,7 @@ 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;
@@ -503,17 +495,13 @@ 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, pattern_last, pglob, limitp)
-       Char *pattern, *pattern_last;
-       glob_t *pglob;
-       size_t *limitp;
+glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
 {
        Char pathbuf[MAXPATHLEN];
 
@@ -531,12 +519,8 @@ glob1(pattern, pattern_last, pglob, limitp)
  * meta characters.
  */
 static int
-glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern,
-    pattern_last, pglob, limitp)
-       Char *pathbuf, *pathbuf_last, *pathend, *pathend_last;
-       Char *pattern, *pattern_last;
-       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;
@@ -588,21 +572,18 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern,
                } else
                        /* Need expansion, recurse. */
                        return(glob3(pathbuf, pathbuf_last, pathend,
-                           pathend_last, pattern, pattern_last,
-                           p, pattern_last, pglob, limitp));
+                           pathend_last, pattern, p, pattern_last,
+                           pglob, limitp));
        }
        /* NOTREACHED */
 }
 
 static int
-glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
-    restpattern, restpattern_last, pglob, limitp)
-       Char *pathbuf, *pathbuf_last, *pathend, *pathend_last;
-       Char *pattern, *pattern_last, *restpattern, *restpattern_last;
-       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];
@@ -640,8 +621,8 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
        else
                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)
@@ -689,13 +670,10 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
  *     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;
@@ -747,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;
@@ -759,11 +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)
@@ -796,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;
@@ -813,9 +788,7 @@ globfree(pglob)
 }
 
 static DIR *
-g_opendir(str, pglob)
-       register Char *str;
-       glob_t *pglob;
+g_opendir(Char *str, glob_t *pglob)
 {
        char buf[MAXPATHLEN];
 
@@ -833,10 +806,7 @@ 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];
 
@@ -848,10 +818,7 @@ g_lstat(fn, sb, pglob)
 }
 
 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];
 
@@ -863,9 +830,7 @@ g_stat(fn, sb, pglob)
 }
 
 static Char *
-g_strchr(str, ch)
-       Char *str;
-       int ch;
+g_strchr(Char *str, int ch)
 {
        do {
                if (*str == ch)
@@ -875,10 +840,7 @@ g_strchr(str, ch)
 }
 
 static int
-g_Ctoc(str, buf, len)
-       register const Char *str;
-       char *buf;
-       u_int len;
+g_Ctoc(const Char *str, char *buf, u_int len)
 {
 
        while (len--) {
@@ -890,11 +852,9 @@ g_Ctoc(str, buf, len)
 
 #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.116406 seconds and 4 git commands to generate.