[Re: Dot files always first in directory?]

devusr at relay.nswc.navy.mil devusr at relay.nswc.navy.mil
Sat May 6 06:16:51 AEST 1989


>> Jonathan I. Kamens <jik at athena.mit.edu> :
>> 
>> It it safe to assume when writing a program which manipulates
>> directories that . and .. will always be the first two entries in a
>> directory?

> Michael J. Chinni <mchinni at pica.army.mil> :
>On our systems (DoD Army) we have a program which uses several files that
>begin with a "," for storage.  These all apear before "." and ".." in the
>directory listings.  [...]  Also, users sometimes create [such] files [...]

but michael, just because ls reports the files in that order doesn't
mean that they are stored in the directory in that order.  no, the
"dot and dot-dot come first" assumption is invalid for other reasons:
doug gwyn mentioned one, and i can think of other scenarios where ..
gets unlinked and relinked to some other inode.  

however, i think that there is a tradeoff between simple code which is
going to work in 98% of the existing environments, and (marginally)
more complicated code which will work everywhere :-)  folks need to
decide just how portable their program should be, and whether the effort
to get to that level is warranted.  in this case, it doesn't seem to
be that hard to cover all the possibilities.

BTW, scandir(3) provides an easy way to exclude dot-files.  perhaps
its use is called for in this case.

/dave

---
Dave Paulson	dpaulso at relay.nswc.navy.mil	(703)663-2137
"I've upped my standards; now up yours" -- Pat Paulsen



More information about the Comp.unix.wizards mailing list