MODULEOSErrorPosix EXPORTSOSError ,OSErrorPosix ; IMPORT Atom, AtomList, Cerrno, Fmt, OSError, Text, Uerror; VAR cache := ARRAY [0..Uerror.Max] OF Atom.T {NIL, ..};
The table is initialized lazily.
PROCEDURENewAtom (n: CARDINAL): Atom.T = BEGIN RETURN Atom.FromText("errno=" & Fmt.Int(n)); END NewAtom; PROCEDUREErrnoAtom (n: CARDINAL): Atom.T = BEGIN IF (n < NUMBER (cache)) THEN IF cache[n] = NIL THEN cache[n] := NewAtom(n) END; RETURN cache[n] ELSE RETURN NewAtom (n); END; END ErrnoAtom; EXCEPTION CheckedRuntimeError; <*FATAL CheckedRuntimeError*> PROCEDUREAtomToErrno (a: Atom.T): CARDINAL = VAR t := Atom.ToText(a); n := 0; c: CHAR; BEGIN IF NOT Text.Equal(Text.Sub(t, 0, 6), "errno=") THEN RAISE CheckedRuntimeError END; FOR i := 6 TO Text.Length(t)-1 DO c := Text.GetChar(t, i); IF '0' <= c AND c <= '9' THEN n := n * 10 + (ORD(c) - ORD('0')) ELSE RAISE CheckedRuntimeError END END; RETURN n END AtomToErrno; PROCEDURERaise0 (errno: INTEGER) RAISES {OSError.E} = BEGIN RAISE OSError.E( NEW(AtomList.T, head := ErrnoAtom(errno), tail := NIL)) END Raise0; PROCEDURERaise () RAISES {OSError.E} = BEGIN Raise0(Cerrno.GetErrno()) END Raise; BEGIN END OSErrorPosix.