Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!ucsd!ucbvax!hplabs!hpfcso!hpldola!hp-lsd!bae From: bae@hp-lsd.COS.HP.COM (Bruce Erickson) Newsgroups: comp.sys.hp Subject: Re: DIRECTORY (3C) strangeness Message-ID: <8250016@hp-lsd.COS.HP.COM> Date: 25 Nov 89 19:13:54 GMT References: <616@mmlai.UUCP> Organization: HP Logic Systems Division - ColoSpgs, CO Lines: 24 >While trying out the C DIRECTORY(3C) routines, I noticed >some very strange behavior. When you do a readdir, >the files are returned in what seems to be random >order. At first it appeared that they return in the >order that the files are created, but new files pop >up where ever. I'm not an expert, but I believe that 'readdir' returns the files in the order that they are in the directory inode, which I think is essentially an array of file names, which are placed in the first unused slot. So, when a directory is first created the files are in first-come first-slot basis; after a file is removed, however, I believe that the next created file gets the slot freed up by the removed file. (I am remembering this from an O/S class 8 years ago, so I may be mis- remembering this!) If you need the files in alphabetical order, read them in but stick them in a binary tree (use bsearch(3C) for ease of implementation) then read them back from the binary tree.... Bruce Erickson hp-lsd!bae