Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.wizards Subject: Re: Dot files always first in directory? Summary: Probably, but you can't rely on it (SUMMARY) Message-ID: <11204@bloom-beacon.MIT.EDU> Date: 8 May 89 02:22:07 GMT References: <11108@bloom-beacon.MIT.EDU> <171@attibr.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 36 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@Athena.MIT.EDU Cambridge, MA 02139-4318 Office: 617-253-4261 Home: 617-225-8218