Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
SysIO


NAME

SysIO - system calls for input and output

SYNOPSIS

(* file control options: arguments of Fcntl and Open *)
CONST rdonly = {};
CONST wronly = { 31 };
CONST rdwr = { 30 };
CONST ndelay = { 29 };
CONST append = { 28 };
CONST creat = { 23 };
CONST trunc = { 22 };
CONST excl = { 21 };


(* Whence = (fromStart, fromPos, fromEnd); *) CONST fromStart = 0; CONST fromPos = 1; CONST fromEnd = 2;

(* file descriptor flags *) CONST closeonexec = { 31 };

(* Fcntl requests *) CONST dupfd = 0; CONST getfd = 1; CONST setfd = 2; CONST getfl = 3; CONST setfl = 4; CONST getlk = 5; CONST setlk = 6; CONST setlkw = 7;

TYPE File = SysTypes.File; TYPE Address = SysTypes.Address; TYPE Count = SysTypes.Count; TYPE Protection = INTEGER; TYPE Whence = INTEGER;

PROCEDURE Open(VAR fd: File; filename: ARRAY OF CHAR; options: SET; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : BOOLEAN; PROCEDURE OpenCreat(VAR fd: File; filename: ARRAY OF CHAR; options: SET; protection: Protection; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : BOOLEAN; PROCEDURE Close(fd: File; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : BOOLEAN; PROCEDURE Read(fd: File; buf: Address; cnt: Count; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : Count; PROCEDURE Write(fd: File; buf: Address; cnt: Count; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : Count; PROCEDURE Seek(fd: File; offset: Count; whence: Whence; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Tell(fd: File; VAR offset: Count; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Isatty(fd: File) : BOOLEAN; PROCEDURE Dup(fd: File; VAR newfd: File; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Dup2(fd, newfd: File; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Fcntl(fd: File; request: INTEGER; VAR arg: INTEGER; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : BOOLEAN; PROCEDURE FcntlSet(fd: File; request: INTEGER; flags: SET; errors: RelatedEvents.Object; retry: BOOLEAN; VAR interrupted: BOOLEAN) : BOOLEAN; PROCEDURE FcntlGet(fd: File; request: INTEGER; VAR flags: SET; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Pipe(VAR readfd, writefd: File; errors: RelatedEvents.Object) : BOOLEAN;

DESCRIPTION

SysIO interfaces those UNIX system calls which are related to input and output.

File represents file descriptors which serve as handle for input and output on system call level and are small integers.

The open(2) system calls has two or three parameters. The third parameter is needed in case of file creation to specify the file protection. File creation is indicated by or-ing creat to options. Open and OpenCreat open filename (must be 0X-terminated) under the control of options:

rdonly
read-only access
wronly
write-only access
rdwr
read and write access
ndelay
assures immediate return
append
write accesses cause implicit positioning to end of file
creat
file is to be created
trunc
file is to be truncated to zero length
excl
assures exclusive creation
Options may be given in combination, e.g. creat+excl+rdwr. See SysStat for protection modes.

Isatty tests fd for being associated to a terminal device. This is done by an ioctl(2) system call. Isatty does not generate any events.

Dup and Dup2 realize the equally named system calls of UNIX Edition VII and Berkeley Systems. They are replaced by fcntl(2) on UNIX System V systems but are supported by SysIO for portability. Dup returns a new file descriptor in newfd which is a synomym for fd (i.e. both point to the same entry of the open file table). Dup2 works like Dup but causes newfd to be the synonym. If newfd was opened it is closed first.

Fcntl implements the equally named system call. FcntlSet and FcntlGet are more convenient interfaces to Fcntl. Following requests are supported:

dupfd
duplicate file descriptor
getfd
get file desc flags (closeonexec)
setfd
set file desc flags (closeonexec)
getfl
get file flags
setfl
set file flags (ndelay, append)
getlk
get file lock
setlk
set file lock
setlkw
set file lock and wait

Close, Read, Write, Seek, Tell, and Pipe realize the equally named system calls. Valid values of the whence parameter of Seek are

fromStart
absolute positioning
fromPos
relative positioning to current position
fromEnd
relative positioning to end of file

DIAGNOSTICS

System call failures lead to events of SysErrors. The errors parameter is passed to SysErrors.Raise. All procedures return FALSE or -1 (SysTypes.Count) in error case.

Some of the system calls may be interrupted. In normal case (retry = FALSE) this causes the appropiate error event to be raised (error code SysErrors.intr) and the system call to be aborted. If retry is TRUE, the system call will be repeated until no interrupt occured. interrupt indicates in both cases whether interrupts occured or not.

SEE ALSO

close(2)
Close
fcntl(2)
Fcntl, FcntlSet, and FcntlGet
open(2)
Open and OpenCreat
pipe(2)
Pipe
read(2)
Read
seek(2)
Seek
tell(2)
Tell
write(2)
Write
SysErrors
handling of failed system calls
SysStat
protection modes

Edited by: borchert, last change: 1992/03/17, revision: 1.7, converted to HTML: 1997/04/28

Oberon || Library || Module Index || Search Engine || Definition || Module