Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!franco@MIKEY.BBN.COM From: franco@MIKEY.BBN.COM (Frank A. Lonigro) Newsgroups: comp.unix.wizards Subject: /bin/test and stat(2) Message-ID: <9723@brl-adm.ARPA> Date: Fri, 9-Oct-87 16:54:17 EDT Article-I.D.: brl-adm.9723 Posted: Fri Oct 9 16:54:17 1987 Date-Received: Sun, 11-Oct-87 16:01:21 EDT Sender: news@brl-adm.ARPA Lines: 63 In article <15069@topaz.rutgers.edu> ron@topaz.rutgers.edu (Ron Natalie) writes: >STAT should never be called with NULL, but it should always work >when called with a zero length string (e.g. ""). > >-Ron Boyd Roberts responds: >Well, I agree with not passing stat() NULL, that's EFAULT city! > >As for "", I couldn't disagree more. The zero length string only >works due to a quirk in namei(). Do you ever see the ``zero length string'' >named file in a directory? No, you don't. > >-Boyd Roberts I agree with Boyd. I was the one who initially brought this subject to unix-wizards and I appreciate all the responses, but I'm afraid no-one has answered my original questions. Everyone has commented on the fact that stat("", &stbuf) (stat of a zero length string) defaults to stat of (DOT) the current directory. This fact was already established prior to my original questions. What I don't believe and understand is that: 1) This is not documented anywhere, BSD4.*, SUN OS, ULTRIX , etc... The fact that stat of zero length string defaults to DOT, that is. I guess maybe I'm supposed to know about the namei() quirk. I'm being sarcastic here! {8-)> 2) Programs like 'ls', 'cd', 'chmod', 'test', 'rmdir', etc.... ^^^^ have all been coded to rely on this default(this can be verified by do something like 'ls ""' or 'chmod ""', etc). In my opinion, is very bad programming practice. And to think that such programs have been coded this way since the beginning of UNIX is hideous. (I realize the previous sentence may be an over-assumption, but I think the quirk in the namei() function has been there ever since the first semi-bug free and run-able UNIX came hot off the presses and since then, systems programmers writing application software for the UNIX OS such as 'ls' and the like relied on this quirk simply because they knew about it in advance and no-one since has bothered to re-code them properly, i.e..checked before hand if the string they are about to pass to stat is a zero length string.) So, let me re-phrase my original questions in hopes of getting them answered properly. Why does Joe/Jane Programmer have to know, in advance, that stat("", &stbuf) will default to stat(".", &stbuf)? (A better re-phrasing of the previous question is, Why does ' test -d "" ' return TRUE when the zero length string is clearly not a directory?) And, equally important, Why do I have to do two tests to find out that a shell variable is a directory (and not a zero length string), whether I use a one line invocation of /bin/test and a boolean or not? I really think that /bin/test should not rely on the default. It should return FALSE in the case of ' test -d "" '. For that matter, all the others should not rely on that default either. Better yet, maybe stat(2) can be recoded to return ERROR if the "path" it was passed is a zero length string. But if for some historical reasons, such programs must remain as relying on the default which implies that stat(2) remains as returning a default, then can the man pages for each state some sort of warning about this fact so future Joe/Jane users will be better informed. -franco