Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: zsh tests (dev-15)



Sorry, I only now got around to looking into this.

Back on Jan 15th, Peter Stephenson wrote:
> 
> Oliver Kiddle wrote:
> > I've never looked at the new tests before but thought I'd run them
> > today. They all pass except one in 07cond.ztst: [[ -e /dev/fd/0 ]]
> > fails. I thought that this /dev/fd/0 stuff was Linux specific (I'm using
> > AIX 3.2) so what is it doing as part of the zsh tests? Is zsh trying to
> > emulate them on other systems? If so, maybe AIX's /dev/fd0 and similar
> > devices (which I think are for the floppy drive) are getting in the way?
> 
> Yes, it's supposed to be emulated:  the conditional expressions part of the
> manual says:
> 
>        In each of the above expressions, if file is of  the  form
>        `/dev/fd/n',  where n is an integer, then the test applied
>        to the open file whose descriptor number is n, even if the
>        underlying  system does not support the /dev/fd directory.
> 
> so something on your system is confusing it (unless, of course, you're
> really running the test with no stdin).  There's a run-time test for
> this in cond.c:getstat():

The code never reaches getstat() with a -e test. If you look at the big
case statement in cond.c, lines numbered in the 200s, for e, it uses
doaccess. getstat() appears to be used for -O, -G, -N, whatever COND_NT,
COND_OT and COND_EF are and all the options which go via dostat(). Those
using doaccess(), miss out the test Peter refered to in getstat().

The patch below extends emulation of /dev/fd/n to the -a, -e, -r, -w and
-x options.

After a quick look at some man pages, it seems that Linux maybe doesn't
have faccessx(). Is this right? Is there an alternative? Does anyone
know if there are any platforms which don't have faccessx or /dev/fd/x
because if not, we could easily wrap my changes to doaccess() in a
#ifdef after detecting faccessx with autoconf. Am I right to use
ACC_SELF instead of ACC_INVOKER (see
http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/libs/basetrf1/access.htm)?

Oliver Kiddle

--- Src/cond.c.bak	Sat Mar 11 20:13:28 2000
+++ Src/cond.c	Sat Mar 11 20:13:34 2000
@@ -297,6 +297,9 @@
 static int
 doaccess(char *s, int c)
 {
+    if (!strncmp(s, "/dev/fd/", 8))
+	return !faccessx(atoi(s + 8), c, ACC_SELF);
+
     return !access(unmeta(s), c);
 }



Messages sorted by: Reverse Date, Date, Thread, Author