From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2653 invoked from network); 5 Aug 2000 06:25:11 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 5 Aug 2000 06:25:11 -0000 Received: (qmail 16717 invoked by alias); 5 Aug 2000 06:24:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12548 Received: (qmail 16707 invoked from network); 5 Aug 2000 06:24:51 -0000 From: "Bart Schaefer" Message-Id: <1000805062411.ZM16867@candle.brasslantern.com> Date: Sat, 5 Aug 2000 06:24:11 +0000 In-Reply-To: <1000805055142.ZM11497@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "PATCH: Handle ENOENT/ENOTDIR in zpathmax()" (Aug 5, 5:51am) References: <1000805055142.ZM11497@candle.brasslantern.com> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.auc.dk Subject: Re: PATCH: Handle ENOENT/ENOTDIR in zpathmax() MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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