1 /* do not edit automatically generated by mc from FIO. */
2 /* FIO.def provides a simple buffered file input/output library.
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
37 # if !defined (PROC_D)
39 typedef void (*PROC_t
) (void);
40 typedef struct { PROC_t proc
; } PROC
;
48 # define EXTERN extern
51 typedef unsigned int FIO_File
;
53 EXTERN FIO_File FIO_StdIn
;
54 EXTERN FIO_File FIO_StdOut
;
55 EXTERN FIO_File FIO_StdErr
;
58 IsNoError - returns a TRUE if no error has occured on file, f.
61 EXTERN
unsigned int FIO_IsNoError (FIO_File f
);
64 IsActive - returns TRUE if the file, f, is still active.
67 EXTERN
unsigned int FIO_IsActive (FIO_File f
);
70 Exists - returns TRUE if a file named, fname exists for reading.
73 EXTERN
unsigned int FIO_Exists (const char *fname_
, unsigned int _fname_high
);
76 OpenToRead - attempts to open a file, fname, for reading and
78 The success of this operation can be checked by
82 EXTERN FIO_File
FIO_OpenToRead (const char *fname_
, unsigned int _fname_high
);
85 OpenToWrite - attempts to open a file, fname, for write and
87 The success of this operation can be checked by
91 EXTERN FIO_File
FIO_OpenToWrite (const char *fname_
, unsigned int _fname_high
);
94 OpenForRandom - attempts to open a file, fname, for random access
95 read or write and it returns this file.
96 The success of this operation can be checked by
98 towrite, determines whether the file should be
99 opened for writing or reading.
100 newfile, determines whether a file should be
101 created if towrite is TRUE or whether the
102 previous file should be left alone,
103 allowing this descriptor to seek
104 and modify an existing file.
107 EXTERN FIO_File
FIO_OpenForRandom (const char *fname_
, unsigned int _fname_high
, unsigned int towrite
, unsigned int newfile
);
110 Close - close a file which has been previously opened using:
111 OpenToRead, OpenToWrite, OpenForRandom.
112 It is correct to close a file which has an error status.
115 EXTERN
void FIO_Close (FIO_File f
);
116 EXTERN
unsigned int FIO_exists (void * fname
, unsigned int flength
);
117 EXTERN FIO_File
FIO_openToRead (void * fname
, unsigned int flength
);
118 EXTERN FIO_File
FIO_openToWrite (void * fname
, unsigned int flength
);
119 EXTERN FIO_File
FIO_openForRandom (void * fname
, unsigned int flength
, unsigned int towrite
, unsigned int newfile
);
122 FlushBuffer - flush contents of the FIO file, f, to libc.
125 EXTERN
void FIO_FlushBuffer (FIO_File f
);
128 ReadNBytes - reads nBytes of a file into memory area, dest, returning
129 the number of bytes actually read.
130 This function will consume from the buffer and then
131 perform direct libc reads. It is ideal for large reads.
134 EXTERN
unsigned int FIO_ReadNBytes (FIO_File f
, unsigned int nBytes
, void * dest
);
137 ReadAny - reads HIGH(a) bytes into, a. All input
138 is fully buffered, unlike ReadNBytes and thus is more
139 suited to small reads.
142 EXTERN
void FIO_ReadAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
145 WriteNBytes - writes nBytes from memory area src to a file
146 returning the number of bytes actually written.
147 This function will flush the buffer and then
148 write the nBytes using a direct write from libc.
149 It is ideal for large writes.
152 EXTERN
unsigned int FIO_WriteNBytes (FIO_File f
, unsigned int nBytes
, void * src
);
155 WriteAny - writes HIGH(a) bytes onto, file, f. All output
156 is fully buffered, unlike WriteNBytes and thus is more
157 suited to small writes.
160 EXTERN
void FIO_WriteAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
163 WriteChar - writes a single character to file, f.
166 EXTERN
void FIO_WriteChar (FIO_File f
, char ch
);
169 EOF - tests to see whether a file, f, has reached end of file.
172 EXTERN
unsigned int FIO_EOF (FIO_File f
);
175 EOLN - tests to see whether a file, f, is about to read a newline.
176 It does NOT consume the newline. It reads the next character
177 and then immediately unreads the character.
180 EXTERN
unsigned int FIO_EOLN (FIO_File f
);
183 WasEOLN - tests to see whether a file, f, has just read a newline
187 EXTERN
unsigned int FIO_WasEOLN (FIO_File f
);
190 ReadChar - returns a character read from file, f.
191 Sensible to check with IsNoError or EOF after calling
195 EXTERN
char FIO_ReadChar (FIO_File f
);
198 UnReadChar - replaces a character, ch, back into file, f.
199 This character must have been read by ReadChar
200 and it does not allow successive calls. It may
201 only be called if the previous read was successful,
202 end of file or end of line seen.
205 EXTERN
void FIO_UnReadChar (FIO_File f
, char ch
);
208 WriteLine - writes out a linefeed to file, f.
211 EXTERN
void FIO_WriteLine (FIO_File f
);
214 WriteString - writes a string to file, f.
217 EXTERN
void FIO_WriteString (FIO_File f
, const char *a_
, unsigned int _a_high
);
220 ReadString - reads a string from file, f, into string, a.
221 It terminates the string if HIGH is reached or
222 if a newline is seen or an error occurs.
225 EXTERN
void FIO_ReadString (FIO_File f
, char *a
, unsigned int _a_high
);
228 WriteCardinal - writes a CARDINAL to file, f.
229 It writes the binary image of the CARDINAL.
233 EXTERN
void FIO_WriteCardinal (FIO_File f
, unsigned int c
);
236 ReadCardinal - reads a CARDINAL from file, f.
237 It reads a bit image of a CARDINAL
241 EXTERN
unsigned int FIO_ReadCardinal (FIO_File f
);
244 GetUnixFileDescriptor - returns the UNIX file descriptor of a file.
245 Useful when combining FIO.mod with select
246 (in Selective.def - but note the comments in
247 Selective about using read/write primatives)
250 EXTERN
int FIO_GetUnixFileDescriptor (FIO_File f
);
253 SetPositionFromBeginning - sets the position from the beginning
257 EXTERN
void FIO_SetPositionFromBeginning (FIO_File f
, long int pos
);
260 SetPositionFromEnd - sets the position from the end of the file.
263 EXTERN
void FIO_SetPositionFromEnd (FIO_File f
, long int pos
);
266 FindPosition - returns the current absolute position in file, f.
269 EXTERN
long int FIO_FindPosition (FIO_File f
);
272 GetFileName - assigns, a, with the filename associated with, f.
275 EXTERN
void FIO_GetFileName (FIO_File f
, char *a
, unsigned int _a_high
);
278 getFileName - returns the address of the filename associated with, f.
281 EXTERN
void * FIO_getFileName (FIO_File f
);
284 getFileNameLength - returns the number of characters associated with
288 EXTERN
unsigned int FIO_getFileNameLength (FIO_File f
);
291 FlushOutErr - flushes, StdOut, and, StdErr.
294 EXTERN
void FIO_FlushOutErr (void);