Dot files always first in directory?
Jonathan I. Kamens
jik at athena.mit.edu
Mon May 8 12:22:07 AEST 1989
Well, by now there have been any number of intelligent responses to
my original question which confirmed my original suspicions, and any
number of quite moronic responses which talk about how files will
appear before . and .. in the listing when you use ls.
To summarize, most Unix filesystems place . and .. first in the
directory by convention; however, this is not a requirement of the
filesystem, and therefore it should not be relied upon by a program,
especially a program that expects to run on many different
architectures usefully.
One person suggested that I use scandir to filter out . and .. from
a directory before dealing with the entries in it. I might just end
up doing that, but I want to examine the code for scandir first and
find out exactly what it's doing -- it may not be very well-optomized
and therefore time constraints will outweigh its usefulness.
I have at this point modified my code so that it uses a macro
is_dotfile to check each file before doing anything with the file.
The macro is_dotfile is defined as follows:
#define is_dotfile(A) ((*A == '.') && \
((*(A + 1) == '\0') || \
((*(A + 1) == '.') && \
(*(A + 2) == '\0'))))
Using this macro, most runs through the loop will only require one
comparison since most files will not start with `.'.
Thanks to all who responded.
Jonathan Kamens USnail:
MIT Project Athena 410 Memorial Drive, No. 223F
jik at Athena.MIT.EDU Cambridge, MA 02139-4318
Office: 617-253-4261 Home: 617-225-8218
More information about the Comp.unix.wizards
mailing list