Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ read(2) — GL1 W2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

fcntl(2)

ioctl(2)

open(2)

pipe(2)

termio(7)

READ(2)  —  Silicon Graphics

NAME

read − read from file

SYNOPSIS

int read (fildes, buf, nbyte)
int fildes;
char ∗buf;
unsigned nbyte;

DESCRIPTION

Fildes is a file descriptor obtained from a creat, open, dup, fcntl, or pipe system call. 

Read attempts to read nbyte bytes from the file associated with fildes into the buffer pointed to by buf.

On devices capable of seeking, the read starts at a position in the file given by the file pointer associated with fildes. Upon return from read, the file pointer is incremented by the number of bytes actually read.

Devices that are incapable of seeking always read from the current position.  The value of a file pointer associated with such a file is undefined. 

Upon successful completion, read returns the number of bytes actually read and placed in the buffer; this number may be less than nbyte if the file is associated with a communication line (see ioctl(2) and termio(7)), or if the number of bytes left in the file is less than nbyte bytes.  A value of 0 is returned when an end-of-file has been reached. 

When attempting to read from an empty pipe (or FIFO):

If O_NDELAY is set, the read will return a 0. 

If O_NDELAY is clear, the read will block until data is written to the file or the file is no longer open for writing. 

When attempting to read a file associated with a tty that has no data currently available:

If O_NDELAY is set, the read will return a 0. 

If O_NDELAY is clear, the read will block until data becomes available. 

Read will fail if one or more of the following are true:

Fildes is not a valid file descriptor open for reading.  ­[EBADF]

Buf points outside the allocated address space.  ­[EFAULT]

RETURN VALUE

Upon successful completion a non-negative integer is returned indicating the number of bytes actually read.  Otherwise, a −1 is returned and errno is set to indicate the error. 

SEE ALSO

creat(2), dup(2), fcntl(2), ioctl(2), open(2), pipe(2), termio(7). 

ASSEMBLER

moveq#3,D0
movlfildes,A0
movlbuf,D1
movlnbytes,A1
trap#0

Carry bit set on failure and cleared on success. 

The number of bytes read is returned in D0. 

Version 2.1  —  January 02, 1985

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026