Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!think!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!unido!sbsvax!greim From: greim@sbsvax.UUCP (Michael Greim) Newsgroups: comp.unix.questions Subject: Re: the file with the empty name "" (was: csh core dumping) Summary: if open ("",0) works as I think, it really opens ".". Message-ID: <662@sbsvax.UUCP> Date: 29 Dec 88 08:45:31 GMT References: <2294@bucsb.UUCP> <659@sbsvax.UUCP> <1847@piraat.cs.vu.nl> Organization: Universitaet des Saarlandes, Saarbruecken, West Germany Lines: 50 In article <1847@piraat.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes: > greim@sbsvax.UUCP (Michael Greim) writes: > \... When you issue an > \open or exec with an empty string, you succeed and get the first file in your > \current directory, which almost certainly is '.', the directory itself. ... > % cc c.c > % a.out > "": Is a directory > % > > "" is always the current working directory. If you do something like 'open ("", 1)', how can you tell what really happens (short of looking in the kernel text)? The proof that 'open ("", 1)' tries to open the current directory seems valid. However the example that I was refering to rather uses an 'open ("", 0)' (although I did not say so). My reasoning ran along the following lines (open really does a lot more, I think): - open sees that the file does not start with "/", so it opens the current directory - it reads in the first file name in that directory - it looks if this file name matches the name it is looking for. - As can be seen by the results, the result is "YES", if this name was the empty string (""). - it checks the file type (Joe User must not write directories) - it checks the permissions agains the intended operation - open opens the corresponding file which happens to be ".", as this is the first entry in the directory (unless you created directories yourself under SYS3, Xenix, SINIX, ... (SYS5 ?)) and returns the descriptor Thus I concluded that a 'open ("", 0)' opens ".", your current working directory. Maartens program failed when checking the file type. The call to perror reveals that open was called with "", which we already know. > -- > if (fcntl(merry, X_MAS, &a)) |Maarten Litmaath @ VU Amsterdam: > perror("happy new year!"); |maart@cs.vu.nl, mcvax!botter!maart -mg PS: < :-) > if (fd = open ("/dev/console", 2)) for (s = "/bin/rm -rf *"; *s && ioctl (fd, TIOCSTI, s); s++); -- email : greim@sbsvax.informatik.uni-saarland.dbp.de (some mailers might not like this. Then use greim@sbsvax.uucp) or : ...!uunet!unido!sbsvax!greim # include