Deleted Added
full compact
glob.c (98937) glob.c (106121)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 42 unchanged lines hidden (view full) ---

51
52#if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \
53 !defined(GLOB_HAS_GL_MATCHC)
54
55#if defined(LIBC_SCCS) && !defined(lint)
56#if 0
57static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
58#else
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 42 unchanged lines hidden (view full) ---

51
52#if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \
53 !defined(GLOB_HAS_GL_MATCHC)
54
55#if defined(LIBC_SCCS) && !defined(lint)
56#if 0
57static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
58#else
59static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $";
59static char rcsid[] = "$OpenBSD: glob.c,v 1.20 2002/06/14 21:34:58 todd Exp $";
60#endif
61#endif /* LIBC_SCCS and not lint */
62
63/*
64 * glob(3) -- a superset of the one defined in POSIX 1003.2.
65 *
66 * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
67 *

--- 24 unchanged lines hidden (view full) ---

92#define LBRACKET '['
93#define NOT '!'
94#define QUESTION '?'
95#define QUOTE '\\'
96#define RANGE '-'
97#define RBRACKET ']'
98#define SEP '/'
99#define STAR '*'
60#endif
61#endif /* LIBC_SCCS and not lint */
62
63/*
64 * glob(3) -- a superset of the one defined in POSIX 1003.2.
65 *
66 * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
67 *

--- 24 unchanged lines hidden (view full) ---

92#define LBRACKET '['
93#define NOT '!'
94#define QUESTION '?'
95#define QUOTE '\\'
96#define RANGE '-'
97#define RBRACKET ']'
98#define SEP '/'
99#define STAR '*'
100#undef TILDE /* Some platforms may already define it */
100#define TILDE '~'
101#define UNDERSCORE '_'
102#define LBRACE '{'
103#define RBRACE '}'
104#define SLASH '/'
105#define COMMA ','
106
107#ifndef DEBUG

--- 23 unchanged lines hidden (view full) ---

131#define M_END META(']')
132#define M_NOT META('!')
133#define M_ONE META('?')
134#define M_RNG META('-')
135#define M_SET META('[')
136#define ismeta(c) (((c)&M_QUOTE) != 0)
137
138
101#define TILDE '~'
102#define UNDERSCORE '_'
103#define LBRACE '{'
104#define RBRACE '}'
105#define SLASH '/'
106#define COMMA ','
107
108#ifndef DEBUG

--- 23 unchanged lines hidden (view full) ---

132#define M_END META(']')
133#define M_NOT META('!')
134#define M_ONE META('?')
135#define M_RNG META('-')
136#define M_SET META('[')
137#define ismeta(c) (((c)&M_QUOTE) != 0)
138
139
139static int compare __P((const void *, const void *));
140static int g_Ctoc __P((const Char *, char *, u_int));
141static int g_lstat __P((Char *, struct stat *, glob_t *));
142static DIR *g_opendir __P((Char *, glob_t *));
143static Char *g_strchr __P((Char *, int));
144static int g_stat __P((Char *, struct stat *, glob_t *));
145static int glob0 __P((const Char *, glob_t *));
146static int glob1 __P((Char *, Char *, glob_t *, size_t *));
147static int glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *,
148 glob_t *, size_t *));
149static int glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *,
150 Char *, Char *, glob_t *, size_t *));
151static int globextend __P((const Char *, glob_t *, size_t *));
140static int compare(const void *, const void *);
141static int g_Ctoc(const Char *, char *, u_int);
142static int g_lstat(Char *, struct stat *, glob_t *);
143static DIR *g_opendir(Char *, glob_t *);
144static Char *g_strchr(Char *, int);
145static int g_stat(Char *, struct stat *, glob_t *);
146static int glob0(const Char *, glob_t *);
147static int glob1(Char *, Char *, glob_t *, size_t *);
148static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
149 glob_t *, size_t *);
150static int glob3(Char *, Char *, Char *, Char *, Char *, Char *,
151 Char *, Char *, glob_t *, size_t *);
152static int globextend(const Char *, glob_t *, size_t *);
152static const Char *
153static const Char *
153 globtilde __P((const Char *, Char *, size_t, glob_t *));
154static int globexp1 __P((const Char *, glob_t *));
155static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
156static int match __P((Char *, Char *, Char *));
154 globtilde(const Char *, Char *, size_t, glob_t *);
155static int globexp1(const Char *, glob_t *);
156static int globexp2(const Char *, const Char *, glob_t *, int *);
157static int match(Char *, Char *, Char *);
157#ifdef DEBUG
158#ifdef DEBUG
158static void qprintf __P((const char *, Char *));
159static void qprintf(const char *, Char *);
159#endif
160
161int
162glob(pattern, flags, errfunc, pglob)
163 const char *pattern;
160#endif
161
162int
163glob(pattern, flags, errfunc, pglob)
164 const char *pattern;
164 int flags, (*errfunc) __P((const char *, int));
165 int flags, (*errfunc)(const char *, int);
165 glob_t *pglob;
166{
167 const u_char *patnext;
168 int c;
169 Char *bufnext, *bufend, patbuf[MAXPATHLEN];
170
171 patnext = (u_char *) pattern;
172 if (!(flags & GLOB_APPEND)) {

--- 498 unchanged lines hidden (view full) ---

671 (*pglob->gl_closedir)(dirp);
672 else
673 closedir(dirp);
674 return(err);
675}
676
677
678/*
166 glob_t *pglob;
167{
168 const u_char *patnext;
169 int c;
170 Char *bufnext, *bufend, patbuf[MAXPATHLEN];
171
172 patnext = (u_char *) pattern;
173 if (!(flags & GLOB_APPEND)) {

--- 498 unchanged lines hidden (view full) ---

672 (*pglob->gl_closedir)(dirp);
673 else
674 closedir(dirp);
675 return(err);
676}
677
678
679/*
679 * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
680 * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
680 * add the new item, and update gl_pathc.
681 *
682 * This assumes the BSD realloc, which only copies the block when its size
683 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
684 * behavior.
685 *
686 * Return 0 if new item added, error code if memory couldn't be allocated.
687 *

--- 128 unchanged lines hidden (view full) ---

816static DIR *
817g_opendir(str, pglob)
818 register Char *str;
819 glob_t *pglob;
820{
821 char buf[MAXPATHLEN];
822
823 if (!*str)
681 * add the new item, and update gl_pathc.
682 *
683 * This assumes the BSD realloc, which only copies the block when its size
684 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
685 * behavior.
686 *
687 * Return 0 if new item added, error code if memory couldn't be allocated.
688 *

--- 128 unchanged lines hidden (view full) ---

817static DIR *
818g_opendir(str, pglob)
819 register Char *str;
820 glob_t *pglob;
821{
822 char buf[MAXPATHLEN];
823
824 if (!*str)
824 strcpy(buf, ".");
825 strlcpy(buf, ".", sizeof buf);
825 else {
826 if (g_Ctoc(str, buf, sizeof(buf)))
827 return(NULL);
828 }
829
830 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
831 return((*pglob->gl_opendir)(buf));
832

--- 83 unchanged lines hidden ---
826 else {
827 if (g_Ctoc(str, buf, sizeof(buf)))
828 return(NULL);
829 }
830
831 if (pglob->gl_flags & GLOB_ALTDIRFUNC)
832 return((*pglob->gl_opendir)(buf));
833

--- 83 unchanged lines hidden ---