[Top] [Prev] [Next]

read, write, stream - read, write, or stream file

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 (fd, buf, nbytes)

The read function reads nbytes bytes of data from the current offset in the file associated with fd into array buf.

The file offset is advanced by the number of bytes read so that subsequent reads will obtain the next data from the file.

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. The number of bytes read is returned as the functional value of read. A return value of 0 is conventionally interpreted as end of file.

write (fd, buf, nbytes)

The write function writes nbytes bytes of data from array buf to the file associated with fd at the current file offset.

The offset is advanced by the number of bytes written so that subsequent writes will deposit data after the previously written data.

The number of bytes actually written is returned by write. It should be regarded as an error if this is not the same as requested.

stream (src, dst, bufsiz)

The stream function 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 (returning a count that does not match the request). The stream function returns the number of bytes actually copied. The implementation may be more efficient than a read / write loop in the application, but is otherwise equivalent to calling read and write directly.

See Also
Limbo System Module

dup - duplicate an open file descriptor

open, create - open/create a file for reading or writing

bufio - buffered input/output module in Chapter 15



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.