(* Copyright (C) 1989, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* Last modified on Wed Nov 4 11:20:42 MET 1992 by preschern *) (* modified on Tue Jun 9 14:10:37 PDT 1992 by kalsow *) (* modified on Mon Nov 18 14:52:27 PST 1991 by muller *) (* Note, that we do not care for FILE structures - * this means they are not closed (they are not garbage * collected because Ustdio.FILE = ADDRESS). A clean * implementation should include FILE structures in Rd'ers * and Wr'ers. *) UNSAFE MODULE FileStream; IMPORT Unix, M3toC, IOFailure, Rd, Wr, UFileRd, UFileWr, Thread, Ustdio; PROCEDURE OpenRead (nm: TEXT): Rd.T RAISES {Rd.Failure} = VAR stream: Ustdio.FILE; BEGIN stream := Ustdio.fopen (M3toC.TtoS (nm), M3toC.TtoS ("r")); IF (stream = NIL) THEN RAISE Rd.Failure (IOFailure.open); END; RETURN (UFileRd.New (Ustdio.fileno(stream))); END OpenRead; PROCEDURE OpenWrite (nm: TEXT): Wr.T RAISES {Wr.Failure} = VAR stream: Ustdio.FILE; BEGIN stream := Ustdio.fopen (M3toC.TtoS (nm), M3toC.TtoS ("w")); IF (stream = NIL) THEN RAISE Rd.Failure (IOFailure.open); END; RETURN (UFileWr.New (Ustdio.fileno(stream))); END OpenWrite; PROCEDURE OpenAppend (nm: TEXT): Wr.T RAISES {Wr.Failure} = <*FATAL Thread.Alerted*> VAR stream: Ustdio.FILE; BEGIN stream := Ustdio.fopen (M3toC.TtoS (nm), M3toC.TtoS ("A")); IF (stream = NIL) THEN RAISE Rd.Failure (IOFailure.open); END; RETURN (UFileWr.New (Ustdio.fileno(stream))); END OpenAppend; PROCEDURE OpenWriteOrAppend (nm: TEXT; flags: INTEGER): Wr.T RAISES {Wr.Failure} = VAR stream: Ustdio.FILE; BEGIN stream := Ustdio.fopen (M3toC.TtoS (nm), M3toC.TtoS ("a")); IF (stream = NIL) THEN RAISE Rd.Failure (IOFailure.open); END; RETURN (UFileWr.New (Ustdio.fileno(stream))); END OpenWriteOrAppend; BEGIN END FileStream.