SYS-READ(2)                                           SYS-READ(2)

     NAME
          read, write, stream - read or write file

     SYNOPSIS
          include "sys.m";
          sys := load Sys Sys->PATH;

          read:   fn(fd: ref FD, buf: array of byte, nbytes: int): int;
          write:  fn(fd: ref FD, buf: array of byte, nbytes: int): int;
          stream: fn(src, dst: ref FD, bufsiz: int): int;

     DESCRIPTION
          Read reads nbytes bytes of data from the offset in the file
          associated with fd into memory at buf. The file 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.

          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
          bytes actually written is returned.  It should be regarded
          as an error if this is not the same as requested.

          Stream continually reads data from src, using a buffer of
          bufsiz bytes, and writes the data to dst. It copies data
          until a read fails (returning zero bytes or an error) or a
          write fails.  Stream returns the number of bytes actually
          copied.  The implementation may be more efficient than a
          read/write loop in the application, but is otherwise equiva-
          lent to calling read and write directly.

     SEE ALSO
          bufio(2), sys-intro(2), sys-dup(2), sys-open(2)

     Page 1                       Plan 9            (printed 11/18/24)