96 lines · 1.9 KB · Text
RawDownload
.TH READ 2.SH NAMEread, readn, write, pread, pwrite \- read or write file.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.Blong read(int fd, void *buf, long nbytes).PP.Blong readn(int fd, void *buf, long nbytes).PP.Blong write(int fd, void *buf, long nbytes).PP.Blong pread(int fd, void *buf, long nbytes, vlong offset).PP.Blong pwrite(int fd, void *buf, long nbytes, vlong offset).SH DESCRIPTION.I Readreads.I nbytesbytes of datafrom the offset in the file associated with.I fdinto memory at.IR buf .The 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.I Readnis just like read, but does successive.I readcalls until.I nbyteshave been read, or a read system callreturns a non-positive count..PP.I 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 characters actually written is returned.It should be regarded as an errorif this is not the same as requested..PP.I Preadand.I Pwriteare equivalent to a.IR seek (2)to.I offsetfollowed by a.I reador.IR write .By combining the operations in a single atomic call, they more closelymatch the 9P protocol(see.IR intro (5))and, more important,permit multiprocess programs to execute multiple concurrentread and write operations on the same file descriptorwithout interference..SH SOURCE.B /sys/src/libc/9syscall.br.B /sys/src/libc/port/readn.c.SH SEE ALSO.IR intro (2),.IR dirread (2),.IR dup (2),.IR open (2),.IR pipe (2),.IR readv (2).SH DIAGNOSTICSThese functions set.IR errstr .