READDIR(2)                                             READDIR(2)

     NAME
          readdir - read directory and sort files

     SYNOPSIS
          include "readdir.m";
          readdir := load Readdir Readdir->PATH;

          NAME, ATIME, MTIME, SIZE, NONE: con iota;
          COMPACT:    con (1<<4);
          DESCENDING: con (1<<5);
          init:  fn(path: string, sortkey: int): (array of ref Dir, int);

     DESCRIPTION
          Readdir reads the contents of the directory path and sorts
          the resulting array according to sortkey.

          Each element in the returned array is a reference to one Dir
          element in the array formed by the dirread system call.
          Readdir also returns the number of entries read, or -1 on
          failure.

          The sorting criteria for the returned array are based on
          sortkey as follows:

          NAME   Sort files alphabetically by name.

          ATIME  Sort files by access time, most recently accessed
                 first.

          MTIME  Sort files by modification time, most recently modi-
                 fied first.

          SIZE   Sort files by size, largest file first.

          NONE   Files are left in directory order, unsorted.

          If the value DESCENDING is or'd into any of the values
          above, except NONE, the order of sorting is reversed.

          The sort used is stable, of particular importance in the
          presence of duplicate names in a union mount.  If the value
          COMPACT is or'd into any of the values above, including
          NONE, only the first (outermost) entry with a given name
          will be returned from reading a union mount, if names are
          duplicated in the union.

     SOURCE
          /appl/lib/readdir.b

     SEE ALSO

     Page 1                       Plan 9            (printed 11/18/24)

     READDIR(2)                                             READDIR(2)

          sys-dirread(2)

     Page 2                       Plan 9            (printed 11/18/24)