"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libnetbsd/glob.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

glob.c  (tnftp-20151004):glob.c  (tnftp-20200705)
/* $NetBSD: glob.c,v 1.12 2014/05/05 00:20:45 lukem Exp $ */ /* $NetBSD: glob.c,v 1.13 2020/07/05 10:03:09 lukem Exp $ */
/* from: NetBSD: glob.c,v 1.34 2013/02/21 18:17:43 christos Exp */ /* from: NetBSD: glob.c,v 1.34 2013/02/21 18:17:43 christos Exp */
/* /*
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Guido van Rossum. * Guido van Rossum.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
skipping to change at line 36 skipping to change at line 36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#if 0
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#else
__RCSID(" NetBSD: glob.c,v 1.38 2017/05/08 14:42:16 christos Exp ");
#endif
#endif /* LIBC_SCCS and not lint */
#endif
/* /*
* glob(3) -- a superset of the one defined in POSIX 1003.2. * glob(3) -- a superset of the one defined in POSIX 1003.2.
* *
* The [!...] convention to negate a range is supported (SysV, Posix, ksh). * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
* *
* Optional extra services, controlled by flags not defined by POSIX: * Optional extra services, controlled by flags not defined by POSIX:
* *
* GLOB_MAGCHAR: * GLOB_MAGCHAR:
* Set in gl_flags if pattern contained a globbing character. * Set in gl_flags if pattern contained a globbing character.
* GLOB_NOMAGIC: * GLOB_NOMAGIC:
skipping to change at line 64 skipping to change at line 77
* GLOB_PERIOD: * GLOB_PERIOD:
* allow metacharacters to match leading dots in filenames. * allow metacharacters to match leading dots in filenames.
* GLOB_NO_DOTDIRS: * GLOB_NO_DOTDIRS:
* . and .. are hidden from wildcards, even if GLOB_PERIOD is set. * . and .. are hidden from wildcards, even if GLOB_PERIOD is set.
* gl_matchc: * gl_matchc:
* Number of matches in the current invocation of glob. * Number of matches in the current invocation of glob.
*/ */
#include "tnftp.h" #include "tnftp.h"
#define NO_GETPW_R
#undef TILDE /* XXX: AIX 4.1.5 has this in <sys/ioctl.h> */
#ifndef __UNCONST
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#endif
#if 0 #if 0
#include "namespace.h"
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <glob.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_NBTOOL_CONFIG_H
#define NO_GETPW_R
#endif #endif
#define NO_GETPW_R #endif
#define GLOB_LIMIT_STRING 65536 /* number of readdirs */ #define GLOB_LIMIT_STRING 524288 /* number of readdirs */
#define GLOB_LIMIT_STAT 128 /* number of stat system calls */ #define GLOB_LIMIT_STAT 128 /* number of stat system calls */
#define GLOB_LIMIT_READDIR 16384 /* total buffer size of path stri ngs */ #define GLOB_LIMIT_READDIR 65536 /* total buffer size of path stri ngs */
#define GLOB_LIMIT_PATH 1024 /* number of path elements */ #define GLOB_LIMIT_PATH 1024 /* number of path elements */
#define GLOB_LIMIT_BRACE 128 /* Number of brace calls */ #define GLOB_LIMIT_BRACE 128 /* Number of brace calls */
struct glob_limit { struct glob_limit {
size_t l_string; size_t l_string;
size_t l_stat; size_t l_stat;
size_t l_readdir; size_t l_readdir;
size_t l_brace; size_t l_brace;
}; };
#undef TILDE /* XXX: AIX 4.1.5 has this in <sys/ioctl.h> */
/* /*
* XXX: For NetBSD 1.4.x compatibility. (kill me l8r) * XXX: For NetBSD 1.4.x compatibility. (kill me l8r)
*/ */
#ifndef _DIAGASSERT #ifndef _DIAGASSERT
#define _DIAGASSERT(a) #define _DIAGASSERT(a)
#endif #endif
#define DOLLAR '$' #define DOLLAR '$'
#define DOT '.' #define DOT '.'
#define EOS '\0' #define EOS '\0'
skipping to change at line 177 skipping to change at line 200
static const Char *globtilde(const Char *, Char *, size_t, glob_t *); static const Char *globtilde(const Char *, Char *, size_t, glob_t *);
static int globexp1(const Char *, glob_t *, struct glob_limit *); static int globexp1(const Char *, glob_t *, struct glob_limit *);
static int globexp2(const Char *, const Char *, glob_t *, int *, static int globexp2(const Char *, const Char *, glob_t *, int *,
struct glob_limit *); struct glob_limit *);
static int match(const Char *, const Char *, const Char *); static int match(const Char *, const Char *, const Char *);
#ifdef DEBUG #ifdef DEBUG
static void qprintf(const char *, Char *); static void qprintf(const char *, Char *);
#endif #endif
int int
glob(const char * pattern, int flags, int (*errfunc)(const char *, glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *,
int), glob_t * pglob) int), glob_t * __restrict pglob)
{ {
const unsigned char *patnext; const unsigned char *patnext;
int c; int c;
Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
struct glob_limit limit = { 0, 0, 0, 0 }; struct glob_limit limit = { 0, 0, 0, 0 };
_DIAGASSERT(pattern != NULL); _DIAGASSERT(pattern != NULL);
patnext = (const unsigned char *) pattern; patnext = (const unsigned char *) pattern;
if (!(flags & GLOB_APPEND)) { if (!(flags & GLOB_APPEND)) {
skipping to change at line 927 skipping to change at line 950
(newsize + limit->l_string) >= GLOB_LIMIT_STRING) (newsize + limit->l_string) >= GLOB_LIMIT_STRING)
goto nospace; goto nospace;
return copy == NULL ? GLOB_NOSPACE : 0; return copy == NULL ? GLOB_NOSPACE : 0;
nospace: nospace:
errno = 0; errno = 0;
return GLOB_NOSPACE; return GLOB_NOSPACE;
} }
/* /*
* pattern matching function for filenames. Each occurrence of the * * pattern matching function for filenames.
* pattern causes a recursion level.
*/ */
static int static int
match(const Char *name, const Char *pat, const Char *patend) match(const Char *name, const Char *pat, const Char *patend)
{ {
int ok, negate_range; int ok, negate_range;
Char c, k; Char c, k;
const Char *patNext, *nameNext, *nameStart, *nameEnd;
_DIAGASSERT(name != NULL); _DIAGASSERT(name != NULL);
_DIAGASSERT(pat != NULL); _DIAGASSERT(pat != NULL);
_DIAGASSERT(patend != NULL); _DIAGASSERT(patend != NULL);
patNext = pat;
while (pat < patend) { nameStart = nameNext = name;
c = *pat++; nameEnd = NULL;
while (pat < patend || *name) {
c = *pat;
if (*name == EOS)
nameEnd = name;
switch (c & M_MASK) { switch (c & M_MASK) {
case M_ALL: case M_ALL:
while (pat < patend && (*pat & M_MASK) == M_ALL) while ((pat[1] & M_MASK) == M_ALL) pat++;
pat++; /* eat consecutive '*' */ patNext = pat;
if (pat == patend) nameNext = name + 1;
return 1; pat++;
for (; !match(name, pat, patend); name++) continue;
if (*name == EOS)
return 0;
return 1;
case M_ONE: case M_ONE:
if (*name++ == EOS) if (*name == EOS)
return 0; break;
break; pat++;
name++;
continue;
case M_SET: case M_SET:
ok = 0; ok = 0;
if ((k = *name++) == EOS) if ((k = *name) == EOS)
return 0; break;
pat++;
name++;
if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
++pat; ++pat;
while (((c = *pat++) & M_MASK) != M_END) while (((c = *pat++) & M_MASK) != M_END)
if ((*pat & M_MASK) == M_RNG) { if ((*pat & M_MASK) == M_RNG) {
if (c <= k && k <= pat[1]) if (c <= k && k <= pat[1])
ok = 1; ok = 1;
pat += 2; pat += 2;
} else if (c == k) } else if (c == k)
ok = 1; ok = 1;
if (ok == negate_range) if (ok == negate_range)
return 0; break;
break; continue;
default: default:
if (*name++ != c) if (*name != c)
return 0; break;
break; pat++;
name++;
continue;
}
if (nameNext != nameStart
&& (nameEnd == NULL || nameNext <= nameEnd)) {
pat = patNext;
name = nameNext;
continue;
} }
return 0;
} }
return *name == EOS; return 1;
} }
/* Free allocated data belonging to a glob_t structure. */ /* Free allocated data belonging to a glob_t structure. */
void void
globfree(glob_t *pglob) globfree(glob_t *pglob)
{ {
size_t i; size_t i;
char **pp; char **pp;
_DIAGASSERT(pglob != NULL); _DIAGASSERT(pglob != NULL);
 End of changes. 21 change blocks. 
32 lines changed or deleted 70 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)