Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!spdcc!m2c!frog!john From: john@frog.UUCP (John Woods, Software) Newsgroups: comp.unix.wizards Subject: Re: /bin/test and stat(2) Message-ID: <1671@frog.UUCP> Date: Fri, 16-Oct-87 16:28:00 EDT Article-I.D.: frog.1671 Posted: Fri Oct 16 16:28:00 1987 Date-Received: Sun, 18-Oct-87 09:16:23 EDT References: <9721@brl-adm.ARPA> Organization: Superfrog Heaven [ CRDS, Framingham MA ] Lines: 59 In article <9721@brl-adm.ARPA>,franco@MIKEY.BBN.COM (Frank A. Lonigro) writes: >>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 >>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 > What I don't believe and understand is that...: > 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). Wondrously false. This is NOT verified by 'ls ""', because ls is just handing the kernel that string ""; ls has no hand in it whatsoever. > 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)? Personally, I think that "" being equivalent to "." is a handy feature, if you don't trust the convention "." will be present in every directory (it isn't at all hard to curdle things so this isn't true). A story: UNOS (CRDS's SVID-compliant operating system) used to allow "" as a synonym for ".", because it made the code easier. One of our customers complained that this was a bug, because their application had a code section roughly (VERY roughly, I never saw their code, just the complaint): while (fred == NULL) { printf("What file should I use? "); gets(buffer); if ((fred = fopen(buffer, "r")) == NULL) printf("no such file.\"); } I argued strenuously that their application should check for the user just typing newline, and probably ought to do some sanity checking of the file that gets opened (what if they type "."???). Unfortunately, others here felt that calling "" an illegal file name was a good idea, and would placate this idiot at the same time. So where does this leave J. Programmer? If a shell script is to work on System V, then "" is the name of no file, and can't be depended on. If a shell script is to work on 4.nBSD or Version 6 or Version 7, then "" *IS* the name of a file, and can't be depended on NOT TO EXIST. If you are on a system where "" names a file, and you don't want your software to let "" name a file, then you have to special case your code to not allow "". -- John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101 ...!decvax!frog!john, ...!mit-eddie!jfw, jfw@eddie.mit.edu "Cutting the space budget really restores my faith in humanity. It eliminates dreams, goals, and ideals and lets us get straight to the business of hate, debauchery, and self-annihilation." -- Johnny Hart