1 (* RTfio.mod implement default FIO based methods.
3 Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
27 IMPLEMENTATION MODULE RTfio
;
29 FROM RTio
IMPORT GetFile
;
30 FROM errno
IMPORT geterrno
;
32 FROM FIO
IMPORT File
, ReadChar
, UnReadChar
, WriteChar
, ReadNBytes
,
33 WriteNBytes
, IsActive
,
34 WriteLine
, EOF
, WasEOLN
, IsNoError
;
38 doreadchar - returns a CHAR from the file associated with, g.
41 PROCEDURE doreadchar (g
: GenDevIF
; d
: DeviceTablePtr
) : CHAR ;
53 dounreadchar - pushes a CHAR back onto the file associated with, g.
56 PROCEDURE dounreadchar (g
: GenDevIF
; d
: DeviceTablePtr
; ch
: CHAR) : CHAR ;
69 dogeterrno - returns the errno relating to the generic device.
72 PROCEDURE dogeterrno (g
: GenDevIF
; d
: DeviceTablePtr
) : INTEGER ;
79 dorbytes - reads upto, max, bytes setting, actual, and
80 returning FALSE if an error (not due to eof)
84 PROCEDURE dorbytes (g
: GenDevIF
; d
: DeviceTablePtr
;
87 VAR actual
: CARDINAL) : BOOLEAN ;
93 actual
:= ReadNBytes(f
, max
, to
) ;
94 RETURN( IsNoError(f
) )
103 PROCEDURE dowbytes (g
: GenDevIF
; d
: DeviceTablePtr
;
106 VAR actual
: CARDINAL) : BOOLEAN ;
112 actual
:= WriteNBytes(f
, nBytes
, from
) ;
113 RETURN( IsNoError(f
) )
119 dowriteln - attempt to write an end of line marker to the
120 file and returns TRUE if successful.
123 PROCEDURE dowriteln (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
127 f
:= GetFile(d^.cid
) ;
129 RETURN( IsNoError(f
) )
134 iseof - returns TRUE if end of file has been seen.
137 PROCEDURE iseof (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
149 iseoln - returns TRUE if end of line is seen.
152 PROCEDURE iseoln (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
164 iserror - returns TRUE if an error was seen on the device.
167 PROCEDURE iserror (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
173 RETURN( IsActive(f
) AND (NOT IsNoError(f
)) )