Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!uw-june!ka From: ka@uw-june.UUCP (Kenneth Almquist) Newsgroups: comp.unix.wizards Subject: Re: /bin/test and stat(2) Message-ID: <3282@uw-june.UUCP> Date: Tue, 13-Oct-87 17:56:35 EDT Article-I.D.: uw-june.3282 Posted: Tue Oct 13 17:56:35 1987 Date-Received: Thu, 15-Oct-87 04:07:13 EDT References: <9721@brl-adm.ARPA> Organization: U of Washington, CSCI, Seattle Lines: 39 > 1) The fact that stat of zero length string defaults to DOT...is > not documented anywhere, BSD4.*, SUN OS, ULTRIX , etc... In the 4.3 BSD manual, under INTRO(2), in the section labelled "Definitions", is a definition of "Path Name" which states in part: "A null path name refers to the current directory." > 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?) Another rephrasing of the question is "Why does Joe/Jane Programmer have to know, in advance, about path names to test whether a path name refers to a directory?" The zero length string clearly (:-)) refers to a directory. > ...maybe stat(2) can be recoded to return ERROR if the "path" it was > passed is a zero length string. This is a reasonable suggestion. As I understand it, originally the null string was used to refer to the current directory, *except* that a null string at the beginning of a file name containing a slash referred to the root directory. (Thus "a//b" referred to "a/b", but "/b" referred to "{root directory}/b".) Exceptions like this are painful; and eventually "." was added as an alternative way to refer to the current directory. The advantage of "." over "" is that when you can append the string "/b" to the string ".", you get what you expect: a path name referring to a file in the directory ".". But the old way of referring to the current directory was retained; presumably for backward compatibility. The result is that people like Frank are told that "." refers to the current directory, but are not told about the alternative "" since "" is presumably obsolete. It's easy to say RTFM, but there really should not be two ways to refer to the current directory. One of the advantages of UN*X is that early in its life it had a small installation base which made it easier to remove features. Too bad "" wasn't removed. Kenneth Almquist