Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Handle ENOENT/ENOTDIR in zpathmax()
- X-seq: zsh-workers 12548
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: Handle ENOENT/ENOTDIR in zpathmax()
- Date: Sat, 5 Aug 2000 06:24:11 +0000
- In-reply-to: <1000805055142.ZM11497@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <1000805055142.ZM11497@xxxxxxxxxxxxxxxxxxxxxxx>
On Aug 5,  5:51am, Bart Schaefer wrote:
} +	/* else                                                          *
} +	 * Either we're at the root (tail == dir) or we're on the first  *
} +	 * component of a relative path (tail == NULL).  Either way we   *
} +	 * have nothing to do here, the error from pathconf() is real.   *
} +	 * Perhaps our current working directory has been removed?       */
I just realized that the above mishandles base cases of the recursion.
(I have the stupid hardwired glibc pathconf so I can't easily test that
branch.)  That is, I suspect `mkdir notadir' or `mkdir /notadir' would
fail with 12547 and a working pathconf().
So the below might call pathconf() twice if dir = "." and the current
directory has been removed, or if pathconf("/") fails, but I figured both
of those are rare enough not to be worth a special-case test in the code.
I also decided to go back to letting pathconf() choke on NULL or "" if it
wants to.
Index: Src/compat.c
===================================================================
@@ -133,8 +133,6 @@
 {
     long pathmax;
 
-    if (!dir || !*dir)
-	dir = ".";
     errno = 0;
     if ((pathmax = pathconf(dir, _PC_PATH_MAX)) >= 0) {
 	/* This code is redundant if pathconf works correctly, but   *
@@ -152,18 +150,19 @@
 	    *tail = 0;
 	    pathmax = zpathmax(dir);
 	    *tail = '/';
-	    if (pathmax > 0) {
-		if (strlen(dir) < pathmax)
-		    return pathmax;
-		else
-		    errno = ENAMETOOLONG;
-	    }
+	} else {
+	    errno = 0;
+	    if (tail)
+		pathmax = pathconf("/", _PC_PATH_MAX);
+	    else
+		pathmax = pathconf(".", _PC_PATH_MAX);
 	}
-	/* else                                                          *
-	 * Either we're at the root (tail == dir) or we're on the first  *
-	 * component of a relative path (tail == NULL).  Either way we   *
-	 * have nothing to do here, the error from pathconf() is real.   *
-	 * Perhaps our current working directory has been removed?       */
+	if (pathmax > 0) {
+	    if (strlen(dir) < pathmax)
+		return pathmax;
+	    else
+		errno = ENAMETOOLONG;
+	}
     }
     if (errno)
 	return -1;
-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   
Messages sorted by:
Reverse Date,
Date,
Thread,
Author