Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ read(2) — SunOS 0.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

dup(2)

open(2)

pipe(2)

socket(2)

socketpair(2)

READ(2)  —  System Interface Manual — System Calls

NAME

read, readv − read input

SYNOPSIS

read(d, buf, nbytes)
int d;
char ∗buf;
int nbytes;

#include <sys/uio.h>

readv(d, iov, iovlen)
int d;
struct iovec ∗iov;
int iovlen;

DESCRIPTION

Read attempts to read nbytes of data from the object referenced by the descriptor d into the buffer pointed to by buf.  Readv performs the same action, but scatters the input data into the iovlen buffers specified by the members of the iovec array: iov[0], iov[1], etc. 

On objects capable of seeking, the read starts at a position given by the pointer associated with d, see lseek(2). Upon return from read, the pointer is incremented by the number of bytes actually read.

Objects that are not capable of seeking always read from the current position.  The value of the pointer associated with such a object is undefined. 

Upon successful completion, read returns the number of bytes actually read and placed in the buffer.  The system guarantees to read the number of bytes requested if the descriptor references a file which has that many bytes left before the end-of-file, but in no other cases. 

If the returned value is 0, then end-of-file has been reached. 

RETURN VALUE

Upon successful completion an integer is returned indicating the number of bytes actually read.  Othewise, a −1 is returned and the global variable errno is set to indicate the error. 

ERRORS

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

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

[EFAULT] Buf points outside the allocated address space. 

[EINTR] A read from a slow device was interrupted before any data arrived by the delivery of a signal. 

SEE ALSO

dup(2), open(2), pipe(2), socket(2), socketpair(2)

DIAGNOSTICS

As mentioned, 0 is returned when the end of the file has been reached.  If the read was otherwise unsuccessful the return value is −1.  Many conditions can generate an error: physical I/O errors, bad buffer address, preposterous nbytes, file descriptor not that of an input file. 

Sun System Release 0.3  —  31 March 1983

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