Oberon || Library || Module Index || Search Engine || Definition || Module
CONST illegalMode = 0; (* mode doesn't equal one of legal modes given below *) CONST invalidFd = 1; (* invalid file descriptor given to OpenFd *) CONST errorcodes = 2; TYPE ErrorCode = SHORTINT; TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: ErrorCode; END; VAR error: Events.EventType; VAR errormsg: ARRAY errorcodes OF Events.Message;
CONST read = 0; write = 1; rdwr = 2; create = 4; condcreate = 8; TYPE Mode = SHORTINT; (* read, write, rdwr, read+create, write+create, rdwr+create, read+condcreate, write+condcreate, rdwr+condcreate *) TYPE Stream = POINTER TO StreamRec; TYPE StreamRec = RECORD (Streams.StreamRec) file: SysTypes.File; (* readonly *) interrupted: BOOLEAN; (* EINTR for last operation? *) retry: BOOLEAN; (* retry on interrupts? *) END;
PROCEDURE Open(VAR s: Streams.Stream; filename: ARRAY OF CHAR; mode: Mode; bufmode: Streams.BufMode; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE OpenFd(VAR s: Streams.Stream; fd: SysTypes.File; mode: Mode; bufmode: Streams.BufMode; errors: RelatedEvents.Object) : BOOLEAN;
The buffering mode bufmode should be one of Streams.onebuf (normal buffering), Streams.bufpool (buffer cache), Streams.nobuf (unbuffered and thus very inefficient), and Streams.linebuf (suitable for line oriented terminal input and output). OpenFd opens a stream for a given file descriptor. The mode of the stream must be compatible to the mode of fd. Streams returned by Open and OpenFd are of type UnixFiles.Stream.
UnixFiles connects the standard streams Streams.stdin, Streams.stdout, and Streams.stderr to the file descriptors 0, 1, and 2 during initialization. The buffering mode of Streams.stdin and Streams.stdout is Streams.linebuf in case of terminal devices and Streams.onebuf for all other files. Streams.stderr is unbuffered. The access mode is rdwr for Streams.stdin and Streams.stdout and write for Streams.stderr.
Errors during the access of the stream are converted into events of RelatedEvents. By default, these events are being queued.
UnixFiles uses some interruptible system calls. By default, operations are retried in case of interruptions. Optionally, the retry field may be set to FALSE. In this case interruptions may lead to error events. The interrupt field indicates whether the last operation was interrupted or not.
UnixFiles checks the opened file for being seekable. In case of special devices this cannot be examined in all cases without trying a seek operation. This, however, is not done to avoid unnecessary error events.
Oberon || Library || Module Index || Search Engine || Definition || Module