summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-01-31 17:06:28 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-01-31 17:06:28 +0000
commit0418f3e7b0782907509711edde851dcde7f73b68 (patch)
tree983ebaf424a6fbca2c132be793d0b2d130bafc6e
parentfbb007212bb551796932ed005cb8565568daa59b (diff)
Add GLOB_NOESCAPE to turn off backslash escaping and make backslash escaping
the default. For xpg4.2.
-rw-r--r--include/glob.h3
-rw-r--r--lib/libc/gen/glob.331
-rw-r--r--lib/libc/gen/glob.c10
3 files changed, 25 insertions, 19 deletions
diff --git a/include/glob.h b/include/glob.h
index 7c5e677e01a..f14102213bb 100644
--- a/include/glob.h
+++ b/include/glob.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: glob.h,v 1.3 1997/09/01 18:44:23 millert Exp $ */
+/* $OpenBSD: glob.h,v 1.4 1998/01/31 17:06:26 millert Exp $ */
/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
/*
@@ -81,6 +81,7 @@ typedef struct {
#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
+#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
#endif
/* Error values returned by glob(3) */
diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3
index 0541c15fab0..ad6705e7477 100644
--- a/lib/libc/gen/glob.3
+++ b/lib/libc/gen/glob.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: glob.3,v 1.5 1998/01/31 16:51:38 millert Exp $
+.\" $OpenBSD: glob.3,v 1.6 1998/01/31 17:06:27 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -184,9 +184,15 @@ consisting of only
.Fa pattern ,
with the number of total pathnames is set to 1, and the number of matched
pathnames set to 0.
-If
-.Dv GLOB_QUOTE
-is set, its effect is present in the pattern returned.
+.It Dv GLOB_NOESCAPE
+By default,
+.Fn glob
+uses the backslash
+.Pq Ql \e
+character for quoting: every occurrence of
+a backslash followed by a character in the pattern is replaced by that
+character, avoiding any special interpretation of the character.
+This option disables that behavior.
.It Dv GLOB_NOSORT
By default, the pathnames are sorted in ascending
.Tn ASCII
@@ -248,11 +254,10 @@ is provided to simplify implementing the historic
.Xr csh 1
globbing behavior and should probably not be used anywhere else.
.It Dv GLOB_QUOTE
-Use the backslash
+This option has no effect as using the backslash
.Pq Ql \e
-character for quoting: every occurrence of
-a backslash followed by a character in the pattern is replaced by that
-character, avoiding any special interpretation of the character.
+character for quoting is now the default. It is included only
+for compatibility with older sources.
.It Dv GLOB_TILDE
Expand patterns that start with
.Ql ~
@@ -410,10 +415,11 @@ execvp("ls", g.gl_pathv);
.Sh STANDARDS
The
.Fn glob
-function is expected to be
+function is expected to conform to
.St -p1003.2
-compatible with the exception
-that the flags
+and
+.St -xpg4.2 .
+Note, however, that the flags
.Dv GLOB_ALTDIRFUNC,
.Dv GLOB_BRACE
.Dv GLOB_MAGCHAR,
@@ -426,8 +432,7 @@ and the fields
and
.Fa gl_flags
should not be used by applications striving for strict
-.Tn POSIX
-conformance.
+standards conformance.
.Sh HISTORY
The
.Fn glob
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 07628304896..08ec8125cc1 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#else
-static char rcsid[] = "$OpenBSD: glob.c,v 1.6 1997/09/01 18:40:33 millert Exp $";
+static char rcsid[] = "$OpenBSD: glob.c,v 1.7 1998/01/31 17:06:27 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -175,7 +175,10 @@ glob(pattern, flags, errfunc, pglob)
bufnext = patbuf;
bufend = bufnext + MAXPATHLEN;
- 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) {
@@ -188,9 +191,6 @@ glob(pattern, flags, errfunc, pglob)
else
*bufnext++ = c;
}
- else
- while (bufnext < bufend && (c = *patnext++) != EOS)
- *bufnext++ = c;
*bufnext = EOS;
if (flags & GLOB_BRACE)