about summary refs log tree commit diff
path: root/Src/Zle/compctl.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-09-11 10:05:23 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-09-11 10:05:23 +0000
commit7b927aeac7ed5be0b3de8476e9f0b8fb88199b3d (patch)
tree54a917caa111e62ac01c13f43b78dab0b1dfb363 /Src/Zle/compctl.c
parent6c887892f9e6261f65767f6fcbeedd27c1137f16 (diff)
downloadzsh-7b927aeac7ed5be0b3de8476e9f0b8fb88199b3d.tar.gz
zsh-7b927aeac7ed5be0b3de8476e9f0b8fb88199b3d.tar.xz
zsh-7b927aeac7ed5be0b3de8476e9f0b8fb88199b3d.zip
22660: unmetafy directory for opendir() etc. in compctl
Diffstat (limited to 'Src/Zle/compctl.c')
-rw-r--r--Src/Zle/compctl.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index 4389c434b..b8ed66260 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -2127,9 +2127,9 @@ gen_matches_files(int dirs, int execs, int all)
 {
     DIR *d;
     struct stat buf;
-    char *n, p[PATH_MAX], *q = NULL, *e;
+    char *n, p[PATH_MAX], *q = NULL, *e, *pathpref;
     LinkList l = NULL;
-    int ns = 0, ng = opts[NULLGLOB], test, aw = addwhat;
+    int ns = 0, ng = opts[NULLGLOB], test, aw = addwhat, pathpreflen;
 
     opts[NULLGLOB] = 1;
 
@@ -2145,12 +2145,22 @@ gen_matches_files(int dirs, int execs, int all)
 	all = execs = 0;
     }
     /* Open directory. */
-    if ((d = opendir((prpre && *prpre) ? prpre : "."))) {
+    if (prpre && *prpre) {
+	pathpref = dupstring(prpre);
+	unmetafy(pathpref, &pathpreflen);
+	/* system needs NULL termination, not provided by unmetafy */
+	pathpref[pathpreflen] = '\0';
+    } else {
+	pathpref = NULL;
+	pathpreflen = 0;
+    }
+    if ((d = opendir(pathpref ? pathpref : "."))) {
 	/* If we search only special files, prepare a path buffer for stat. */
-	if (!all && prpre) {
-	    strcpy(p, prpre);
-	    q = p + strlen(prpre);
+	if (!all && pathpreflen) {
+	    /* include null byte we carefully added */
+	    memcpy(p, pathpref, pathpreflen+1);
 	}
+	q = p + pathpreflen;
 	/* Fine, now read the directory. */
 	while ((n = zreaddir(d, 1)) && !errflag) {
 	    /* Ignore files beginning with `.' unless the thing we found on *