36 lines · 1.3 KB · Text
RawDownload
= dirread: read directory     include "sys.m";    sys := load Sys Sys->PATH;     dirread:  fn(fd: ref FD): (int, array of Dir); Dirread reads the contents of the directory pointed to by theopen file descriptor fd,  returning  a  tuple  containing  anarray  with  one Dir structure for each directory entry read.These Dir structures are equivalent to the result of  a  statcall  on  each  file in the directory.  See sys-stat(2) for adescription of stat and Dir. A successful dirread returns a tuple  giving  the  number  ofentries  read  and  the resulting array.  A return of (0,nil)indicates the end of the directory.   Directory  entries  arevariable  length  in  general; the file offset is advanced bythe number of bytes actually read. Seeks (see sys-seek(2)) are allowed on  directories  only  toseek to the start. In  general,  several calls to dirread will be needed to readthe whole directory.  Readdir  (2)  provides  functions  thatreturn all the directory entries at once, optionally sorted. == see ALSOreaddir(2),   sys-intro(2),  sys-open(2),  sys-read(2),  sys-seek(2), sys-stat(2) == diagnosticsThe integer in dirread's return tuple has a value  of  -1  onerror,  and 0 on end of file.  The array element of the tupleis nil in both cases.