Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!hal!ncoast!allbery From: allbery@ncoast.ORG (Brandon S. Allbery) Newsgroups: comp.unix.wizards Subject: Re: Dot files always first in directory? Message-ID: <13641@ncoast.ORG> Date: 14 May 89 19:43:02 GMT References: <19473@adm.BRL.MIL> <28440@cci632.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 43 As quoted from <28440@cci632.UUCP> by tvf@cci632.UUCP (Tom Frauenhofer): +--------------- | In article <19473@adm.BRL.MIL> mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) writes: | >> From: "Jonathan I. Kamens" | >> It it safe to assume when writing a program which manipulates | >> directories that . and .. will always be the first two entries in a | >> directory? | | BTW, I wouldn't depend on "." and ".." being the first two listings in | a directory. It may be a convention, but I fail to see how hard it would be | to just write a little extra code to skip these entries when you find them. +--------------- That's the way I do it; I also check for d_name[0] == '.' first to speed up the check, as there are almost always more files not beginning with '.' than files that do in any non-trivial case. (That is, the speed doesn't matter in someone's home directory that contains six dot files and no non-dot files, as happens on a certain system I use when a new user is created.) Also: once, I managed to confuse a System III directory when attempting to relink the kernel. (I passed the wrong path to make, and it proceeded to attempt to create the new kernel as "..", which "ld" promptly DELETED when it couldn't write on it.) After discovering this, I used /etc/link to replace the ".." entry... by which time I had created a file for some reason, so ".." ended up somewhere in the middle of the directory. Fsck didn't care about its new location; neither did ls or anything else. One final comment: if you KNOW that the file system is Unix, you can be reasonably certain that the first two entries are "." and "..". (Excepting, of course, situations like the above.) In the case of the HP9000 Unix that was mentioned previously, I've heard that the underlying filesystem is NOT a Unix filesystem; the kernel maps it onto an HP file system, and "." and ".." are magic cookies handled by namei. This is likely to be common whenever Unix is running on top of something else, e.g. (early?) Primix, DG's version of Unix, Eunice, etc., if the underlying OS does not itself use something similar. ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@ncoast.org uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu Send comp.sources.misc submissions to comp-sources-misc@ NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser