summaryrefslogtreecommitdiffstats
path: root/bin/sh/expand.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/expand.c')
-rw-r--r--bin/sh/expand.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 7d98737..2b522ab 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -1,6 +1,8 @@
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1997-2005
+ * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
@@ -1150,10 +1152,11 @@ expmeta(char *enddir, char *name)
struct dirent *dp;
int atend;
int matchdot;
+ int esc;
metaflag = 0;
start = name;
- for (p = name ; ; p++) {
+ for (p = name; esc = 0, *p; p += esc + 1) {
if (*p == '*' || *p == '?')
metaflag = 1;
else if (*p == '[') {
@@ -1178,12 +1181,14 @@ expmeta(char *enddir, char *name)
break;
else if (*p == CTLQUOTEMARK)
continue;
- else if (*p == CTLESC)
- p++;
- if (*p == '/') {
- if (metaflag)
- break;
- start = p + 1;
+ else {
+ if (*p == CTLESC)
+ esc++;
+ if (p[esc] == '/') {
+ if (metaflag)
+ break;
+ start = p + esc + 1;
+ }
}
}
if (metaflag == 0) { /* we've reached the end of the file name */
@@ -1229,7 +1234,8 @@ expmeta(char *enddir, char *name)
atend = 1;
} else {
atend = 0;
- *endname++ = '\0';
+ *endname = '\0';
+ endname += esc + 1;
}
matchdot = 0;
p = start;
@@ -1257,7 +1263,7 @@ expmeta(char *enddir, char *name)
}
closedir(dirp);
if (! atend)
- endname[-1] = '/';
+ endname[-esc - 1] = esc ? CTLESC : '/';
}
OpenPOWER on IntegriCloud