Are . and .. first?
Donn Terry
donn at hpfcdc.HP.COM
Sat May 13 00:37:00 AEST 1989
It is not safe to assume that . and .. are first (or even that they
do or do not exist as directory entries). In developing POSIX, we
found just about all possible variations.
Try this one (as super-user on System V systems; you can do it in C as
super-user on just about any "classical" system.)
cd /somewhere/child
/etc/unlink ..
touch foo
/etc/link /somewhere ..
This will make "foo" the second entry, and put ".." somewhere else.
On other implementations this sequence might be an error, do nothing
but create foo, or (potentially) crash the system.
The only portable way to deal with directories is to use the directory
library (opendir(), etc.), and then to look for and ignore . and ..
if you find them.
Donn Terry
HP
More information about the Comp.unix.wizards
mailing list