103 lines · 1.9 KB · Text
RawDownload
.TH DIRREAD 2.SH NAMEdirread, dirreadall \- read directory.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.Blong dirread(int fd, Dir **buf).PP.Blong dirreadall(int fd, Dir **buf).PP.B#define	STATMAX	65535U.PP.B#define	DIRMAX	(sizeof(Dir)+STATMAX).SH DESCRIPTIONThe data returned by a.IR read (2)on a directory is a set of complete directory entriesin a machine-independent format, exactly equivalent tothe result of a.IR stat (2)on each file or subdirectory in the directory..I Dirreaddecodes the directory entries into a machine-dependent form.It reads from.IR fdand unpacks the data into an array of.B Dirstructureswhose address is returned in.B *buf(see.IR stat (2)for the layout of a.BR Dir ).The array is allocated with.IR malloc (2)each time.I dirreadis called..PP.I Dirreadallis like.IR dirread ,but reads in the entire directory; by contrast,.I dirreadsteps through a directory one.IR read (2)at a time..PPDirectory entries have variable length.A successful.I readof a directory always returns an integral number of complete directory entries;.I dirreadalways returns complete.B Dirstructures.See.IR read (5)for more information..PPThe constant.B STATMAXis the maximum size that a directory entry can occupy.The constant.B DIRMAXis an upper limit on the size necessary to hold a.B Dirstructure and all the associated data..PP.I Dirreadand.I dirreadallreturn the number of.B Dirstructures filled in.BR buf .The file offset is advanced by the number of bytes actually read..SH SOURCE.B /sys/src/libc/9sys/dirread.c.SH SEE ALSO.IR intro (2),.IR open (2),.IR read (2).SH DIAGNOSTICS.I Dirreadand.I Dirreadallreturn zero for end of file and a negative value for error.In either case,.B *bufis set to.B nilso the pointer can always be freed with impunity..PPThese functions set.IR errstr .