summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/glob.c
diff options
context:
space:
mode:
authormikeh <mikeh@FreeBSD.org>2002-07-17 04:58:09 +0000
committermikeh <mikeh@FreeBSD.org>2002-07-17 04:58:09 +0000
commitcd0195b666c38f44d9ca4b9296f915cf78c02685 (patch)
tree92f6aa408880f10b8b79a3fb6f5189540b25cdd7 /lib/libc/gen/glob.c
parentdd7f21ab90470d396b3c368392f89c1d105594f3 (diff)
downloadFreeBSD-src-cd0195b666c38f44d9ca4b9296f915cf78c02685.zip
FreeBSD-src-cd0195b666c38f44d9ca4b9296f915cf78c02685.tar.gz
Update glob(3) to add all the POSIX required options, specifically:
- add GLOB_NOMATCH return value and use it when we don't get a match - rename GLOB_ABEND to GLOB_ABORTED and use it instead of returning 1 in some places - add GLOB_NOESCAPE flag and retire GLOB_QUOTE to compatibility section Suggestions/advice on correct usage of POSIX defines: wollman
Diffstat (limited to 'lib/libc/gen/glob.c')
-rw-r--r--lib/libc/gen/glob.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index e50c11d..5e159dd 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -182,7 +182,10 @@ glob(pattern, flags, errfunc, pglob)
bufnext = patbuf;
bufend = bufnext + MAXPATHLEN - 1;
- if (flags & GLOB_QUOTE) {
+ if (flags & GLOB_NOESCAPE)
+ while (bufnext < bufend && (c = *patnext++) != EOS)
+ *bufnext++ = c;
+ else {
/* Protect the quoted characters. */
while (bufnext < bufend && (c = *patnext++) != EOS)
if (c == QUOTE) {
@@ -195,9 +198,6 @@ glob(pattern, flags, errfunc, pglob)
else
*bufnext++ = c;
}
- else
- while (bufnext < bufend && (c = *patnext++) != EOS)
- *bufnext++ = c;
*bufnext = EOS;
if (flags & GLOB_BRACE)
@@ -415,8 +415,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
* The main glob() routine: compiles the pattern (optionally processing
* quotes), calls glob1() to do the real pattern matching, and finally
* sorts the list (unless unsorted operation is requested). Returns 0
- * if things went well, nonzero if errors occurred. It is not an error
- * to find no matches.
+ * if things went well, nonzero if errors occurred.
*/
static int
glob0(pattern, pglob, limit)
@@ -493,12 +492,15 @@ glob0(pattern, pglob, limit)
* and the pattern did not contain any magic characters
* GLOB_NOMAGIC is there just for compatibility with csh.
*/
- if (pglob->gl_pathc == oldpathc &&
- ((pglob->gl_flags & GLOB_NOCHECK) ||
- ((pglob->gl_flags & GLOB_NOMAGIC) &&
- !(pglob->gl_flags & GLOB_MAGCHAR))))
- return(globextend(pattern, pglob, limit));
- else if (!(pglob->gl_flags & GLOB_NOSORT))
+ if (pglob->gl_pathc == oldpathc) {
+ if (((pglob->gl_flags & GLOB_NOCHECK) ||
+ ((pglob->gl_flags & GLOB_NOMAGIC) &&
+ !(pglob->gl_flags & GLOB_MAGCHAR))))
+ return(globextend(pattern, pglob, limit));
+ else
+ return(GLOB_NOMATCH);
+ }
+ if (!(pglob->gl_flags & GLOB_NOSORT))
qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
pglob->gl_pathc - oldpathc, sizeof(char *), compare);
return(0);
@@ -557,7 +559,7 @@ glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
(g_stat(pathbuf, &sb, pglob) == 0) &&
S_ISDIR(sb.st_mode)))) {
if (pathend + 1 > pathend_last)
- return (1);
+ return (GLOB_ABORTED);
*pathend++ = SEP;
*pathend = EOS;
}
@@ -572,7 +574,7 @@ glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
if (ismeta(*p))
anymeta = 1;
if (q + 1 > pathend_last)
- return (1);
+ return (GLOB_ABORTED);
*q++ = *p++;
}
@@ -581,7 +583,7 @@ glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
pattern = p;
while (*pattern == SEP) {
if (pathend + 1 > pathend_last)
- return (1);
+ return (GLOB_ABORTED);
*pathend++ = *pattern++;
}
} else /* Need expansion, recurse. */
@@ -611,7 +613,7 @@ glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
struct dirent *(*readdirfunc)();
if (pathend > pathend_last)
- return (1);
+ return (GLOB_ABORTED);
*pathend = EOS;
errno = 0;
@@ -619,10 +621,10 @@ glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
/* TODO: don't call for ENOENT or ENOTDIR? */
if (pglob->gl_errfunc) {
if (g_Ctoc(pathbuf, buf, sizeof(buf)))
- return (GLOB_ABEND);
+ return (GLOB_ABORTED);
if (pglob->gl_errfunc(buf, errno) ||
pglob->gl_flags & GLOB_ERR)
- return (GLOB_ABEND);
+ return (GLOB_ABORTED);
}
return(0);
}
OpenPOWER on IntegriCloud