the file with the empty name "" (was: csh core dumping)
Michael Greim
greim at sbsvax.UUCP
Thu Dec 29 18:45:31 AEST 1988
In article <1847 at piraat.cs.vu.nl>, maart at cs.vu.nl (Maarten Litmaath) writes:
> greim at 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 at 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 at sbsvax.informatik.uni-saarland.dbp.de
(some mailers might not like this. Then use greim at sbsvax.uucp)
or : ...!uunet!unido!sbsvax!greim
# include <disclaimers/std.h>
More information about the Comp.unix.questions
mailing list