aboutsummaryrefslogtreecommitdiff
path: root/posix/glob.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-11-06 00:02:46 +0000
committerUlrich Drepper <drepper@redhat.com>1997-11-06 00:02:46 +0000
commit86187531d302de284b67ac162cf76c60c86bd7da (patch)
tree456f8b37f8e8fa67c16ee0cf6de7b591d9d3d913 /posix/glob.c
parent1618c590382ef16b1942bf39a42aa683a050ff57 (diff)
downloadglibc-86187531d302de284b67ac162cf76c60c86bd7da.tar
glibc-86187531d302de284b67ac162cf76c60c86bd7da.tar.gz
glibc-86187531d302de284b67ac162cf76c60c86bd7da.tar.bz2
glibc-86187531d302de284b67ac162cf76c60c86bd7da.zip
1997-11-06 00:06 Ulrich Drepper <drepper@cygnus.com> * argp/argp-help.c: Optimize a bit by using mempcpy. * elf/dl-load.c: Likewise. * elf/dl-lookup.c: Likewise. * inet/rcmd.c: Likewise. * io/ftw.c: Likewise. * libio/fileops.c: Likewise. * libio/genops.c: Likewise. * libio/obprintf.c: Likewise. * nss/nsswitch.c: Likewise. * posix/execvp.c: Likewise. * posix/getopt.c: Likewise. * posix/glob.c: Likewise. * posix/wordexp.c: Likewise. * stdio-common/vfprintf.c: Likewise. * stdlib/canonicalize.c: Likewise. * stdlib/msort.c: Likewise. * string/argz-replace.c: Likewise. * sysdeps/generic/putenv.c: Likewise. * sysdeps/generic/setenv.c: Likewise. * sysdeps/posix/getcwd.c: Likewise. * sysdeps/posix/ttyname.c: Likewise. * sysdeps/posix/writev.c: Likewise. * time/strftime.c: Likewise. * time/tzfile.c: Likewise. * login/utmp_daemon.c: Use memcpy instead of strcpy where possible. * sunrpc/svcauth_des.c: Likewise. * sysdeps/unix/sysv/linux/gethostname.c: Likewise. * misc/tsearch.c: Use memcpy return value if possible. * posix/regex.c: Likewise. * sysdeps/unix/readdir_r.c: Likewise. * wcsmbc/wcsdup.c: Likewise. * nss/digits_dots.c: Little optimization. * inet/ruserpass.c (ruserpass): Optimize by using stpcpy. (struct toktab): Make tokstr field a const char *. * elf/dl-profile.c: Fix typo. * inet/ether_ntoh.c: Don't use relative #include path. * inet/gethstbynm.c: Likewise. * resolv/inet_pton.c: Likewise. * shadow/sgetspent_r.c: Likewise. * libio/oldfileops.c (_IO_old_file_jumps): Use correct sync and write callbacks. Patch by NIIBE Yutaka <gniibe@mri.co.jp>. * posix/confstr.c: Correct string for _CS_LFS_CFLAGS. Handle _CS_XBS5_* constants. * posix/unistd.h: Add comment describing _XBS5_* constants. * sysdeps/generic/bits/confname.h: Add _CS_XBS5_* constants. * posix/regex.c: Indent preprocessor code. * posix/wordexp.c: Using _itoa_word instead of sprintf. * stdlib/canonicalize.c: Avoid unnecessary copying. Handle NULL and "" arguments correctly according to SUS. * stdlib/test-canon.c: Test "" and NULL argument handling. * sysdeps/posix/writev.c: Correct condition to leave the loop. 1997-11-05 18:13 Ulrich Drepper <drepper@cygnus.com> * nss/getXXbyYY.c: Set buffer to NULL if realloc fails so that possible next call starts with malloc again. Proposed by Joe Keane <jgk@jgk.org>. 1997-11-04 23:57 Ulrich Drepper <drepper@cygnus.com> * configure.in: Correct gcc -pipe test. Patch by Zack Weinberg <zack@rabi.phys.columbia.edu>. * posix/glob.c: Cleanups. Patch by H.J. Lu <hjl@lucon.org>. 1997-11-04 Andreas Jaeger <aj@arthur.rhein-neckar.de> * manual/creature.texi (Feature Test Macros): Add _POSIX_C_SOURCE definition.
Diffstat (limited to 'posix/glob.c')
-rw-r--r--posix/glob.c204
1 files changed, 81 insertions, 123 deletions
diff --git a/posix/glob.c b/posix/glob.c
index 909b4f148c..85747f5a9d 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -374,8 +374,12 @@ glob (pattern, flags, errfunc, pglob)
#endif
/* We know the prefix for all sub-patterns. */
+#ifdef HAVE_MEMPCPY
+ alt_start = mempcpy (onealt, pattern, begin - pattern);
+#else
memcpy (onealt, pattern, begin - pattern);
alt_start = &onealt[begin - pattern];
+#endif
/* Find the first sub-pattern and at the same time find the
rest after the closing brace. */
@@ -951,138 +955,94 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
char *name;
};
struct globlink *names = NULL;
- size_t nfound = 0;
-
- if (!__glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE)))
+ size_t nfound;
+ int meta;
+ int save;
+
+ stream = ((flags & GLOB_ALTDIRFUNC) ?
+ (*pglob->gl_opendir) (directory) :
+ (__ptr_t) opendir (directory));
+ if (stream == NULL)
{
- /* We must check whether the file in this directory exists. */
- stream = ((flags & GLOB_ALTDIRFUNC) ?
- (*pglob->gl_opendir) (directory) :
- (__ptr_t) opendir (directory));
- if (stream == NULL)
- {
- if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
- (flags & GLOB_ERR))
- return GLOB_ABORTED;
- }
- else if (pattern[0] == '\0')
- {
- /* This is a special case for matching directories like in
- "*a/". */
- names = (struct globlink *) __alloca (sizeof (struct globlink));
- names->name = (char *) malloc (1);
- if (names->name == NULL)
- goto memory_error;
- names->name[0] = '\0';
- names->next = NULL;
- nfound = 1;
- }
- else
- while (1)
- {
- struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ?
- (*pglob->gl_readdir) (stream) :
- readdir ((DIR *) stream));
- if (d == NULL)
- break;
- if (! REAL_DIR_ENTRY (d))
- continue;
-
-#ifdef HAVE_D_TYPE
- /* If we shall match only directories use the information
- provided by the dirent if possible. */
- if ((flags & GLOB_ONLYDIR)
- && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
- continue;
-#endif
-
- if (strcmp (pattern, d->d_name) == 0)
- {
- size_t len = NAMLEN (d);
- names =
- (struct globlink *) __alloca (sizeof (struct globlink));
- names->name = (char *) malloc (len + 1);
- if (names->name == NULL)
- goto memory_error;
-#ifdef HAVE_MEMPCPY
- *((char *) mempcpy ((__ptr_t) names->name, pattern, len))
- = '\0';
-#else
- memcpy ((__ptr_t) names->name, pattern, len);
- names->name[len] = '\0';
-#endif
- names->next = NULL;
- nfound = 1;
- break;
- }
- }
+ if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
+ (flags & GLOB_ERR))
+ return GLOB_ABORTED;
+ nfound = 0;
+ meta = 0;
+ }
+ else if (pattern[0] == '\0')
+ {
+ /* This is a special case for matching directories like in
+ "*a/". */
+ names = (struct globlink *) __alloca (sizeof (struct globlink));
+ names->name = (char *) malloc (1);
+ if (names->name == NULL)
+ goto memory_error;
+ names->name[0] = '\0';
+ names->next = NULL;
+ nfound = 1;
+ meta = 0;
}
else
{
- flags |= GLOB_MAGCHAR;
+ nfound = 0;
+ meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
+ if(meta)
+ flags |= GLOB_MAGCHAR;
- stream = ((flags & GLOB_ALTDIRFUNC) ?
- (*pglob->gl_opendir) (directory) :
- (__ptr_t) opendir (directory));
- if (stream == NULL)
+ while (1)
{
- if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
- (flags & GLOB_ERR))
- return GLOB_ABORTED;
- }
- else
- while (1)
- {
- const char *name;
- size_t len;
- struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ?
- (*pglob->gl_readdir) (stream) :
- readdir ((DIR *) stream));
- if (d == NULL)
- break;
- if (! REAL_DIR_ENTRY (d))
- continue;
-
- name = d->d_name;
+ const char *name;
+ size_t len;
+ struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ?
+ (*pglob->gl_readdir) (stream) :
+ readdir ((DIR *) stream));
+ if (d == NULL)
+ break;
+ if (! REAL_DIR_ENTRY (d))
+ continue;
#ifdef HAVE_D_TYPE
- /* If we shall match only directories use the information
- provided by the dirent if possible. */
- if ((flags & GLOB_ONLYDIR)
- && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
- continue;
+ /* If we shall match only directories use the information
+ provided by the dirent call if possible. */
+ if ((flags & GLOB_ONLYDIR)
+ && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
+ continue;
#endif
- if (fnmatch (pattern, name,
- (!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) |
- ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
+ name = d->d_name;
+
+ if ((!meta && strcmp (pattern, name) == 0)
+ || fnmatch (pattern, name,
+ (!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) |
+ ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
#ifdef _AMIGA
- | FNM_CASEFOLD
+ | FNM_CASEFOLD
#endif
) == 0)
- {
- struct globlink *new
- = (struct globlink *) __alloca (sizeof (struct globlink));
- len = NAMLEN (d);
- new->name
- = (char *) malloc (len + 1);
- if (new->name == NULL)
- goto memory_error;
+ {
+ struct globlink *new
+ = (struct globlink *) __alloca (sizeof (struct globlink));
+ len = NAMLEN (d);
+ new->name = (char *) malloc (len + 1);
+ if (new->name == NULL)
+ goto memory_error;
#ifdef HAVE_MEMPCPY
- *((char *) mempcpy ((__ptr_t) new->name, name, len)) = '\0';
+ *((char *) mempcpy ((__ptr_t) new->name, name, len)) = '\0';
#else
- memcpy ((__ptr_t) new->name, name, len);
- new->name[len] = '\0';
+ memcpy ((__ptr_t) new->name, name, len);
+ new->name[len] = '\0';
#endif
- new->next = names;
- names = new;
- ++nfound;
- }
- }
+ new->next = names;
+ names = new;
+ ++nfound;
+ if (!meta)
+ break;
+ }
+ }
}
- if (nfound == 0 && (flags & GLOB_NOMAGIC) &&
- ! __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE)))
+ if (nfound == 0 && (flags & GLOB_NOMAGIC) && !meta)
flags |= GLOB_NOCHECK;
if (nfound == 0 && (flags & GLOB_NOCHECK))
@@ -1124,15 +1084,13 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
pglob->gl_flags = flags;
}
- if (stream != NULL)
- {
- int save = errno;
- if (flags & GLOB_ALTDIRFUNC)
- (*pglob->gl_closedir) (stream);
- else
- closedir ((DIR *) stream);
- __set_errno (save);
- }
+ save = errno;
+ if (flags & GLOB_ALTDIRFUNC)
+ (*pglob->gl_closedir) (stream);
+ else
+ closedir ((DIR *) stream);
+ __set_errno (save);
+
return nfound == 0 ? GLOB_NOMATCH : 0;
memory_error: