(*
    Title: 	FileStream - Definitions
    LastEdit:	"Mon Sep 17 14:11:14 1984"
    Author: 	Mick Jordan
		Acorn Research Centre
*)

DEFINITION MODULE FileStream;
(*
    Streams interface to the UNIX file system.
    Provides the standard file interface as a subset.
*)

FROM Streams IMPORT Stream;

EXPORT QUALIFIED 
    FileMode, 
    ReadByOwner, WriteByOwner, ExecuteByOwner,
    ReadByGroup, WriteByGroup, ExecuteByGroup,
    ReadByWorld, WriteByWorld, ExecuteByWorld,
    CreateInput, CreateOutput, CreateOutputWithMode, CreateInOutput,
    StreamErrorCode;

TYPE FileMode = SET OF [0 .. 8];
(*  File creation modes
*)
CONST
    ReadByOwner = FileMode {8}; WriteByOwner = FileMode {7}; 
    ExecuteByOwner = FileMode {6};

    ReadByGroup = FileMode {5}; WriteByGroup = FileMode {4}; 
    ExecuteByGroup = FileMode {3};

    ReadByWorld = FileMode {2}; WriteByWorld = FileMode {1}; 
    ExecuteByWorld = FileMode {0};

PROCEDURE StreamErrorCode(s: Stream): INTEGER;
(*  Returns the UNIX error code in the event of an error.
*)

(*  The default FileMode used when creating files by CreateOutput.
    Initialised to ReadByOwner+WriteByOwner
                  +ReadByGroup+WriteByGroup
                  +ReadByWorld+WriteByWorld
    Note that this is modified by the current 'umask' setting,  which
    normally strips of the WriteByGroup and WriteByWorld bits.
*)

(*  Padding of the name with a null character, as required by UNIX,
    is performed automatically by the procedures below.
*)

PROCEDURE CreateInput(name: ARRAY OF CHAR): Stream;
(*  Open an input stream to file 'name'.
*)

PROCEDURE CreateOutput(name: ARRAY OF CHAR): Stream;
(*  Open an output stream to file 'name'.
    If the file does not exist it is created with FileMode DefaultMode,
    otherwise it is truncated to zero length.
*)

PROCEDURE CreateInOutput(name: ARRAY OF CHAR): Stream;
(*  Open an input/output stream to file 'name'.
    If the file does not exist it is created with FileMode DefaultMode,
    otherwise it is truncated to zero length.
    It is then closed and re-opened for read and write access.
*)
    
PROCEDURE CreateOutputWithMode(name: ARRAY OF CHAR; mode: FileMode): Stream;
(*  As CreateOutput, but if it does not exist, it is created with
    FileMode = mode.
*)

END FileStream .
