Dot files always first in directory?

Panos Tsirigotis panos at boulder.Colorado.EDU
Fri May 5 14:37:41 AEST 1989


In article <672 at mitisft.Convergent.COM> kemnitz at mitisft.Convergent.COM (Gregory Kemnitz) writes:
>In article <11108 at bloom-beacon.MIT.EDU>, jik at athena.mit.edu (Jonathan I. Kamens) writes:
>> 
>> It it safe to assume when writing a program which manipulates
>> directories that . and .. will always be the first two entries in a
>> directory?
>> 
>> If I can't assume that, then I've got to compare every file in the
>> directory to "." and "..", and this would probably slow the program
>> down even more than it already is.
>> 
>
>After checks on our file system, I found that this assumption is PROBABLY
>correct.  However, this type of thing is EXTREMELY DANGEROUS, unless it is
>part of the definition of the directory structure (It might well be - if it
>is ignore this message and I'll be eating flames).  This type of assumption
>usually leades to unportable code. (will your code run on UNIX forever??)
>...

Copying from dir(5) of the BSD programmer's manual:
	  
->   By convention, the first two entries in each  directory  are
->   for  `.'  and `..'.  

So, as long as the file system is maintained by UNIX it is safe to assume
that the first 2 entries are for for "." and ".." (I assume that System V
follows the same convention; I don't have those manuals available).

Panos Tsirigotis


----------------------------------------------------
| Email address: panos at boulder.colorado.edu        |
----------------------------------------------------



More information about the Comp.unix.wizards mailing list