man(1) Manual page archive


     READ(2)                                                   READ(2)

     NAME
          read, readn, write, pread, pwrite, read9p, write9p - read or
          write file

     SYNOPSIS
          #include <u.h>
          #include <libc.h>

          long read(int fd, void *buf, long nbytes)

          long readn(int fd, void *buf, long nbytes)

          long write(int fd, void *buf, long nbytes)

          long pread(int fd, void *buf, long nbytes, vlong offset)

          long pwrite(int fd, void *buf, long nbytes, vlong offset)

          long read9p(int fd, void *buf, long nbytes)

          long write9p(int fd, void *buf, long nbytes)

     DESCRIPTION
          Read reads nbytes bytes of data from the offset in the file
          associated with fd into memory at buf. The offset is
          advanced by the number of bytes read.  It is not guaranteed
          that all nbytes bytes will be read; for example if the file
          refers to the console, at most one line will be returned.
          In any event the number of bytes read is returned.  A return
          value of 0 is conventionally interpreted as end of file.

          Readn is just like read, but does successive read calls
          until nbytes have been read, or a read system call returns a
          non-positive count.

          Write writes nbytes bytes of data starting at buf to the
          file associated with fd at 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 error if this is not the same as requested.

          Pread and Pwrite equivalent to a seek(2) to offset followed
          by a read or write. By combining the operations in a single
          atomic call, they more closely match the 9P protocol (see
          intro(5)) and, more important, permit multiprocess programs
          to execute multiple concurrent read and write operations on
          the same file descriptor without interference.

          Read9p and write9p are like read and write and are used when
          reading/writing 9P messages to/from a remote file, for

     READ(2)                                                   READ(2)

          example /mnt/term/srv/boot.  9P limits the size of the data
          in a read or write message, normally 8192 bytes.  When
          encapsulating a 9P write request or read reply inside
          another 9P message that limit must be relaxed to make room
          for the extra header.  Read9p and write9p are kludges to
          allow that relaxation.  Using these calls, one can encapsu-
          late 9P messages up to 8 levels deep.

     SOURCE
          /sys/src/libc/9syscall
          /sys/src/libc/port/readn.c

     SEE ALSO
          intro(2), open(2), dup(2), pipe(2)

     DIAGNOSTICS
          These functions set errstr.