forsyth20121205-174063a80cc13 years agoHistory
108 lines · 2.3 KB · Text
RawDownload
.TH SYS-READ 2.SH NAMEread, write, pread, pwrite, stream \- read or write file.SH SYNOPSIS.EXinclude "sys.m";sys := load Sys Sys->PATH; read:   fn(fd: ref FD, buf: array of byte, nbytes: int): int;readn:  fn(fd: ref FD, buf: array of byte, nbytes: int): int;write:  fn(fd: ref FD, buf: array of byte, nbytes: int): int; pread:  fn(fd: ref FD, buf: array of byte, nbytes: int,           offset: big): int;pwrite: fn(fd: ref FD, buf: array of byte, nbytes: int,           offset: big): int; stream: fn(src, dst: ref FD, bufsiz: int): int;.EE.SH DESCRIPTION.B Readreads.I nbytesbytes of data from the offset in the fileassociated with.I fdinto memory at.IR buf .The file offset is advanced by the number of bytes read.It is not guaranteedthat all.I nbytesbytes will be read; for exampleif the file refers to the console, at most one linewill be returned.In any event the number of bytes read is returned.A return value of0 is conventionally interpreted as end of file..PP.B Readncontinues to.B readfrom.I fdsequentially into.IR buf ,until.I nbyteshave been read, or.B readreturns a non-positive count..PP.B Writewrites.I nbytesbytes of data starting at.I bufto the file associated with.I fdat the file offset.The offset is advanced by the number of bytes written.The number of bytes actually written is returned.It should be regarded as an errorif this is not the same as requested..PP.B Preadand.B pwritetake an explicit file.I offsetas a parameter, leaving.IR fd 'scurrent offset untouched;they are otherwise identical in behaviour to.B readand.BR write .They are particulary useful when several processes must access the same.I fdconcurrently and it is inconvenient or undesirable to synchronise their activityto avoid interference..PP.B Streamcontinually reads data from.IR src ,using a buffer of.I bufsizbytes, and writes the data to.IR dst .It copies datauntil a read fails (returningzero bytes or an error) or a write fails..B Streamreturns the number of bytes actually copied.The implementation may be more efficient than a.BR read / writeloop in the application, but is otherwiseequivalent to calling.B readand.B writedirectly..SH SEE ALSO.IR bufio (2),.IR sys-intro (2),.IR sys-dup (2),.IR sys-open (2),.IR read (5)