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-2024 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/>. */
38 # if !defined (PROC_D)
40 typedef void (*PROC_t
) (void);
41 typedef struct { PROC_t proc
; } PROC
;
49 # define EXTERN extern
52 typedef unsigned int FIO_File
;
54 EXTERN FIO_File FIO_StdIn
;
55 EXTERN FIO_File FIO_StdOut
;
56 EXTERN FIO_File FIO_StdErr
;
59 IsNoError - returns a TRUE if no error has occured on file, f.
62 EXTERN
bool FIO_IsNoError (FIO_File f
);
65 IsActive - returns TRUE if the file, f, is still active.
68 EXTERN
bool FIO_IsActive (FIO_File f
);
71 Exists - returns TRUE if a file named, fname exists for reading.
74 EXTERN
bool FIO_Exists (const char *fname_
, unsigned int _fname_high
);
77 OpenToRead - attempts to open a file, fname, for reading and
79 The success of this operation can be checked by
83 EXTERN FIO_File
FIO_OpenToRead (const char *fname_
, unsigned int _fname_high
);
86 OpenToWrite - attempts to open a file, fname, for write and
88 The success of this operation can be checked by
92 EXTERN FIO_File
FIO_OpenToWrite (const char *fname_
, unsigned int _fname_high
);
95 OpenForRandom - attempts to open a file, fname, for random access
96 read or write and it returns this file.
97 The success of this operation can be checked by
99 towrite, determines whether the file should be
100 opened for writing or reading.
101 newfile, determines whether a file should be
102 created if towrite is TRUE or whether the
103 previous file should be left alone,
104 allowing this descriptor to seek
105 and modify an existing file.
108 EXTERN FIO_File
FIO_OpenForRandom (const char *fname_
, unsigned int _fname_high
, bool towrite
, bool newfile
);
111 Close - close a file which has been previously opened using:
112 OpenToRead, OpenToWrite, OpenForRandom.
113 It is correct to close a file which has an error status.
116 EXTERN
void FIO_Close (FIO_File f
);
117 EXTERN
bool FIO_exists (void * fname
, unsigned int flength
);
118 EXTERN FIO_File
FIO_openToRead (void * fname
, unsigned int flength
);
119 EXTERN FIO_File
FIO_openToWrite (void * fname
, unsigned int flength
);
120 EXTERN FIO_File
FIO_openForRandom (void * fname
, unsigned int flength
, bool towrite
, bool newfile
);
123 FlushBuffer - flush contents of the FIO file, f, to libc.
126 EXTERN
void FIO_FlushBuffer (FIO_File f
);
129 ReadNBytes - reads nBytes of a file into memory area, dest, returning
130 the number of bytes actually read.
131 This function will consume from the buffer and then
132 perform direct libc reads. It is ideal for large reads.
135 EXTERN
unsigned int FIO_ReadNBytes (FIO_File f
, unsigned int nBytes
, void * dest
);
138 ReadAny - reads HIGH (a) + 1 bytes into, a. All input
139 is fully buffered, unlike ReadNBytes and thus is more
140 suited to small reads.
143 EXTERN
void FIO_ReadAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
146 WriteNBytes - writes nBytes from memory area src to a file
147 returning the number of bytes actually written.
148 This function will flush the buffer and then
149 write the nBytes using a direct write from libc.
150 It is ideal for large writes.
153 EXTERN
unsigned int FIO_WriteNBytes (FIO_File f
, unsigned int nBytes
, void * src
);
156 WriteAny - writes HIGH (a) + 1 bytes onto, file, f. All output
157 is fully buffered, unlike WriteNBytes and thus is more
158 suited to small writes.
161 EXTERN
void FIO_WriteAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
164 WriteChar - writes a single character to file, f.
167 EXTERN
void FIO_WriteChar (FIO_File f
, char ch
);
170 EOF - tests to see whether a file, f, has reached end of file.
173 EXTERN
bool FIO_EOF (FIO_File f
);
176 EOLN - tests to see whether a file, f, is about to read a newline.
177 It does NOT consume the newline. It reads the next character
178 and then immediately unreads the character.
181 EXTERN
bool FIO_EOLN (FIO_File f
);
184 WasEOLN - tests to see whether a file, f, has just read a newline
188 EXTERN
bool FIO_WasEOLN (FIO_File f
);
191 ReadChar - returns a character read from file, f.
192 Sensible to check with IsNoError or EOF after calling
196 EXTERN
char FIO_ReadChar (FIO_File f
);
199 UnReadChar - replaces a character, ch, back into file, f.
200 This character must have been read by ReadChar
201 and it does not allow successive calls. It may
202 only be called if the previous read was successful,
203 end of file or end of line seen.
206 EXTERN
void FIO_UnReadChar (FIO_File f
, char ch
);
209 WriteLine - writes out a linefeed to file, f.
212 EXTERN
void FIO_WriteLine (FIO_File f
);
215 WriteString - writes a string to file, f.
218 EXTERN
void FIO_WriteString (FIO_File f
, const char *a_
, unsigned int _a_high
);
221 ReadString - reads a string from file, f, into string, a.
222 It terminates the string if HIGH is reached or
223 if a newline is seen or an error occurs.
226 EXTERN
void FIO_ReadString (FIO_File f
, char *a
, unsigned int _a_high
);
229 WriteCardinal - writes a CARDINAL to file, f.
230 It writes the binary image of the CARDINAL.
234 EXTERN
void FIO_WriteCardinal (FIO_File f
, unsigned int c
);
237 ReadCardinal - reads a CARDINAL from file, f.
238 It reads a bit image of a CARDINAL
242 EXTERN
unsigned int FIO_ReadCardinal (FIO_File f
);
245 GetUnixFileDescriptor - returns the UNIX file descriptor of a file.
246 Useful when combining FIO.mod with select
247 (in Selective.def - but note the comments in
248 Selective about using read/write primatives)
251 EXTERN
int FIO_GetUnixFileDescriptor (FIO_File f
);
254 SetPositionFromBeginning - sets the position from the beginning
258 EXTERN
void FIO_SetPositionFromBeginning (FIO_File f
, long int pos
);
261 SetPositionFromEnd - sets the position from the end of the file.
264 EXTERN
void FIO_SetPositionFromEnd (FIO_File f
, long int pos
);
267 FindPosition - returns the current absolute position in file, f.
270 EXTERN
long int FIO_FindPosition (FIO_File f
);
273 GetFileName - assigns, a, with the filename associated with, f.
276 EXTERN
void FIO_GetFileName (FIO_File f
, char *a
, unsigned int _a_high
);
279 getFileName - returns the address of the filename associated with, f.
282 EXTERN
void * FIO_getFileName (FIO_File f
);
285 getFileNameLength - returns the number of characters associated with
289 EXTERN
unsigned int FIO_getFileNameLength (FIO_File f
);
292 FlushOutErr - flushes, StdOut, and, StdErr.
295 EXTERN
void FIO_FlushOutErr (void);