]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/glob.c
Script to turn plain man pages into html now that we want to make html man
[gssapi-openssh.git] / openssh / openbsd-compat / glob.c
index f6a04ea3f4fe3f2efca01fefb22fd50f4f338112..365d4334fc5d6ced0024b242a0042f83bc6bd7b8 100644 (file)
@@ -1,4 +1,3 @@
-/*     $OpenBSD: glob.c,v 1.25 2005/08/08 08:05:34 espie 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. Neither the name of the University nor the names of its contributors
+ * 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
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -31,8 +34,6 @@
  * SUCH DAMAGE.
  */
 
-/* OPENBSD ORIGINAL: lib/libc/gen/glob.c */
-
 #include "includes.h"
 #include <ctype.h>
 
@@ -51,6 +52,14 @@ get_arg_max(void)
 #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.16 2001/04/05 18:36:12 deraadt Exp $";
+#endif
+#endif /* LIBC_SCCS and not lint */
+
 /*
  * glob(3) -- a superset of the one defined in POSIX 1003.2.
  *
@@ -88,7 +97,6 @@ get_arg_max(void)
 #define        RBRACKET        ']'
 #define        SEP             '/'
 #define        STAR            '*'
-#undef TILDE                   /* Some platforms may already define it */
 #define        TILDE           '~'
 #define        UNDERSCORE      '_'
 #define        LBRACE          '{'
@@ -128,31 +136,33 @@ typedef char Char;
 #define        ismeta(c)       (((c)&M_QUOTE) != 0)
 
 
-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 *, Char *, glob_t *, size_t *);
-static int      globextend(const Char *, glob_t *, size_t *);
+static int      compare __P((const void *, const void *));
+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));
+static int      g_stat __P((Char *, struct stat *, glob_t *));
+static int      glob0 __P((const Char *, glob_t *));
+static int      glob1 __P((Char *, Char *, glob_t *, size_t *));
+static int      glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *,
+                   glob_t *, size_t *));
+static int      glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *,
+                   Char *, Char *, glob_t *, size_t *));
+static int      globextend __P((const Char *, glob_t *, size_t *));
 static const 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 *);
+                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 *));
 #ifdef DEBUG
-static void     qprintf(const char *, Char *);
+static void     qprintf __P((const char *, Char *));
 #endif
 
 int
-glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
-    glob_t *pglob)
+glob(pattern, flags, errfunc, pglob)
+       const char *pattern;
+       int flags, (*errfunc) __P((const char *, int));
+       glob_t *pglob;
 {
        const u_char *patnext;
        int c;
@@ -200,7 +210,9 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
  * characters
  */
 static int
-globexp1(const Char *pattern, glob_t *pglob)
+globexp1(pattern, pglob)
+       const Char *pattern;
+       glob_t *pglob;
 {
        const Char* ptr = pattern;
        int rv;
@@ -223,7 +235,10 @@ globexp1(const Char *pattern, glob_t *pglob)
  * If it fails then it tries to glob the rest of the pattern and returns.
  */
 static int
-globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
+globexp2(ptr, pattern, pglob, rv)
+       const Char *ptr, *pattern;
+       glob_t *pglob;
+       int *rv;
 {
        int     i;
        Char   *lm, *ls;
@@ -328,7 +343,11 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
  * expand tilde from the passwd file.
  */
 static const Char *
-globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
+globtilde(pattern, patbuf, patbuf_len, pglob)
+       const Char *pattern;
+       Char *patbuf;
+       size_t patbuf_len;
+       glob_t *pglob;
 {
        struct passwd *pwd;
        char *h;
@@ -396,7 +415,9 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
  * to find no matches.
  */
 static int
-glob0(const Char *pattern, glob_t *pglob)
+glob0(pattern, pglob)
+       const Char *pattern;
+       glob_t *pglob;
 {
        const Char *qpatnext;
        int c, err, oldpathc;
@@ -483,13 +504,17 @@ glob0(const Char *pattern, glob_t *pglob)
 }
 
 static int
-compare(const void *p, const void *q)
+compare(p, q)
+       const void *p, *q;
 {
        return(strcmp(*(char **)p, *(char **)q));
 }
 
 static int
-glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
+glob1(pattern, pattern_last, pglob, limitp)
+       Char *pattern, *pattern_last;
+       glob_t *pglob;
+       size_t *limitp;
 {
        Char pathbuf[MAXPATHLEN];
 
@@ -507,8 +532,12 @@ glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
  * meta characters.
  */
 static int
-glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
-    Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
+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;
 {
        struct stat sb;
        Char *p, *q;
@@ -567,11 +596,14 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
 }
 
 static int
-glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
-    Char *pattern, Char *pattern_last, Char *restpattern,
-    Char *restpattern_last, glob_t *pglob, size_t *limitp)
+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;
 {
-       struct dirent *dp;
+       register struct dirent *dp;
        DIR *dirp;
        int err;
        char buf[MAXPATHLEN];
@@ -582,7 +614,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
         * and dirent.h as taking pointers to differently typed opaque
         * structures.
         */
-       struct dirent *(*readdirfunc)(void *);
+       struct dirent *(*readdirfunc)();
 
        if (pathend > pathend_last)
                return (1);
@@ -607,10 +639,10 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                readdirfunc = pglob->gl_readdir;
        else
-               readdirfunc = (struct dirent *(*)(void *))readdir;
+               readdirfunc = readdir;
        while ((dp = (*readdirfunc)(dirp))) {
-               u_char *sc;
-               Char *dc;
+               register u_char *sc;
+               register Char *dc;
 
                /* Initial DOT must be matched literally. */
                if (dp->d_name[0] == DOT && *pattern != DOT)
@@ -644,7 +676,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
 
 
 /*
- * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
+ * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
  * add the new item, and update gl_pathc.
  *
  * This assumes the BSD realloc, which only copies the block when its size
@@ -658,10 +690,13 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
  *     gl_pathv points to (gl_offs + gl_pathc + 1) items.
  */
 static int
-globextend(const Char *path, glob_t *pglob, size_t *limitp)
+globextend(path, pglob, limitp)
+       const Char *path;
+       glob_t *pglob;
+       size_t *limitp;
 {
-       char **pathv;
-       int i;
+       register char **pathv;
+       register int i;
        u_int newsize, len;
        char *copy;
        const Char *p;
@@ -713,7 +748,8 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp)
  * pattern causes a recursion level.
  */
 static int
-match(Char *name, Char *pat, Char *patend)
+match(name, pat, patend)
+       register Char *name, *pat, *patend;
 {
        int ok, negate_range;
        Char c, k;
@@ -724,10 +760,11 @@ match(Char *name, Char *pat, Char *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)
@@ -760,10 +797,11 @@ match(Char *name, Char *pat, Char *patend)
 
 /* Free allocated data belonging to a glob_t structure. */
 void
-globfree(glob_t *pglob)
+globfree(pglob)
+       glob_t *pglob;
 {
-       int i;
-       char **pp;
+       register int i;
+       register char **pp;
 
        if (pglob->gl_pathv != NULL) {
                pp = pglob->gl_pathv + pglob->gl_offs;
@@ -776,12 +814,14 @@ globfree(glob_t *pglob)
 }
 
 static DIR *
-g_opendir(Char *str, glob_t *pglob)
+g_opendir(str, pglob)
+       register Char *str;
+       glob_t *pglob;
 {
        char buf[MAXPATHLEN];
 
        if (!*str)
-               strlcpy(buf, ".", sizeof buf);
+               strcpy(buf, ".");
        else {
                if (g_Ctoc(str, buf, sizeof(buf)))
                        return(NULL);
@@ -794,7 +834,10 @@ g_opendir(Char *str, glob_t *pglob)
 }
 
 static int
-g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
+g_lstat(fn, sb, pglob)
+       register Char *fn;
+       struct stat *sb;
+       glob_t *pglob;
 {
        char buf[MAXPATHLEN];
 
@@ -806,7 +849,10 @@ g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
 }
 
 static int
-g_stat(Char *fn, struct stat *sb, glob_t *pglob)
+g_stat(fn, sb, pglob)
+       register Char *fn;
+       struct stat *sb;
+       glob_t *pglob;
 {
        char buf[MAXPATHLEN];
 
@@ -818,7 +864,9 @@ g_stat(Char *fn, struct stat *sb, glob_t *pglob)
 }
 
 static Char *
-g_strchr(Char *str, int ch)
+g_strchr(str, ch)
+       Char *str;
+       int ch;
 {
        do {
                if (*str == ch)
@@ -828,7 +876,10 @@ g_strchr(Char *str, int ch)
 }
 
 static int
-g_Ctoc(const Char *str, char *buf, u_int len)
+g_Ctoc(str, buf, len)
+       register const Char *str;
+       char *buf;
+       u_int len;
 {
 
        while (len--) {
@@ -840,9 +891,11 @@ g_Ctoc(const Char *str, char *buf, u_int len)
 
 #ifdef DEBUG
 static void
-qprintf(const char *str, Char *s)
+qprintf(str, s)
+       const char *str;
+       register Char *s;
 {
-       Char *p;
+       register Char *p;
 
        (void)printf("%s:\n", str);
        for (p = s; *p; p++)
This page took 0.203182 seconds and 4 git commands to generate.