Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!rochester!ritcv!moscom!jgp From: jgp@moscom.UUCP (Jim Prescott) Newsgroups: comp.unix.wizards Subject: Re: /bin/test and stat(2) Message-ID: <1063@moscom.UUCP> Date: Sun, 11-Oct-87 04:18:34 EDT Article-I.D.: moscom.1063 Posted: Sun Oct 11 04:18:34 1987 Date-Received: Mon, 12-Oct-87 21:36:43 EDT References: <9723@brl-adm.ARPA> Reply-To: jgp@moscom.UUCP (Jim Prescott) Organization: MOSCOM Corp, E. Rochester, NY Lines: 68 Summary: "" may or may not equal "." but should be documented In article <9723@brl-adm.ARPA> franco@MIKEY.BBN.COM writes: >Everyone has commented on the fact that stat("", &stbuf) defaults to stat >of (DOT) the current directory. This fact was already established prior >to my original questions. Actually under System V passing a null string to a system call returns ENOENT. I tried playing with a few commands on our NCR Tower (SysV.2) /bin/ls '' replaces null string with . /usr/ucb/ls '' prints "cannot stat " test -d '' false csh, -d '' false On our V7 system '' is treated as . by the kernel (namei). Things like ls don't treat '' special. The System V ls actually checks for a null string and changes it into a dot. You can tell the difference with ls '' '', SysV prints the dir name as ".:" and V7 as ":". The ucb ls demonstrates the need for a standard subroutine to print the text message associated with the value of errno, we could call it perror() or something :-) > 2) Programs like 'ls', 'cd', 'chmod', 'test', 'rmdir', etc.... > have all been coded to rely on this default Not to rely on it, they just don't care about it. If the kernel says that the file "" is the same as the file "." it really isn't appropriate for chmod to disagree. Having every program trying to error check arguments to system calls would be silly, the kernel is going to check anyway and it will at least be consistent. > 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 I think it has been in since the beginning. I believe it was considered a feature but wouldn't be surprised if part of the reason was that it was faster, namei was (and to a lesser extent still is) a place where the kernel spends lots of it's time. >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)? If JJ Programer only wants to code on SysVid Compliant machines then they can assume stat("",&b) and test -d "" will return ENOENT and false resepctively. If they want to port their code to the larger (for now) non-SysV world they need to know that the kernel treats "" like "." simply because it does. Even if JJ considers it to be a bug, the fact that it is present on most Unix machines means that it must be catered to. >I really think that /bin/test should not rely on the default. It should >return FALSE in the case of ' test -d "" '. The fewer assumptions user code makes about filenames the better. If it needs to be fixed it needs to be fixed in the kernel. To be portable you need to make both checks yourself since "" is valid on some systems and illegal on others. >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. Systems should document how their namei behaves and how it differs from other systems (the latter being unrealistic except for a comparison against a standard, I'm not sure if sysvid address this or not). As another example, "normal" Unix systems will accept multiple '/'s wherever one is valid. While this could be the same "bug" in namei, I think that "////etc/////foo" involves two directory scans, not nine. This too is non-portable since some systems use "//vaxa/etc/foo" to specify a super-root directory in a network. Since it isn't documented it is probably illegal on some systems. Dealing with the filesystem is a rather common function. Since namei defines most of the user interface with the file system it deserves to be documented in full. Tell whats legal, illegal and both (illegal but happens to work). -- Jim Prescott moscom!jgp@cs.rochester.edu {rutgers,ames,cmcl2}!rochester!moscom!jgp