• Re: opendir/readdir - Don't they access directories in chrono. order ?

    From KP KP@21:1/5 to John F Haugh II on Sun Aug 7 16:58:13 2022
    On Thursday, November 14, 1991 at 6:06:09 AM UTC-8, John F Haugh II wrote:
    [ Not really an internals question, so I'm sending this off to comp.unix.questions. ]
    In article <75...@borg.cs.unc.edu> mirc...@schubert.cs.unc.edu (Jaideep Mirchandani) writes:
    I am trying to run a program which uses opendir/readdir
    to read the entries in a directory. I thought that this would
    access the entries in chronological order, so I set the timestamps of
    all the files in this directory in the order in which I wanted them read, >by using 'touch'.

    Unfortunately, they were not read in time order, so I don't know how
    to control the program's output. Do you know how I can force opendir/readdir >to read my file entries in a certain order.
    readdir() returns the directory entries in some generally random
    order, sort of related to time, but jumbled up as time goes by.
    That is, if you start with an empty directory and add files to
    it one by one, readdir() might give you the entries back in the
    order you entered them. But generally speaking, it doesn't.
    What you will probably have to do is set up a structure containing
    the appropriate st_?time field and a pointer the file's name. Use
    qsort() (or roll your own) and sort the resulting array of file name/timestamp structures.
    --
    John F. Haugh II | I am the NRA. | UUCP: ...!cs.utexas.edu!rpp386!jfh
    Ma Bell: (512) 255-8251 | Shoot a friend today!| Domain: j...@rpp386.cactus.org
    " ... expectation is the mother of disappointment."
    -- Brad Konopik
    In your loolie.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)