Amulets & Armor
v1.02
Open Source Game
|
File IO. More...
Macros | |
#define | MAX_FILES 20 |
Functions | |
T_void | FileClose (T_file file) |
E_Boolean | FileExist (T_byte8 *p_filename) |
T_word32 | FileGetSize (T_byte8 *p_filename) |
T_void * | FileLoad (T_byte8 *p_filename, T_word32 *p_size) |
T_file | FileOpen (T_byte8 *p_filename, E_fileMode mode) |
T_sword32 | FileRead (T_file file, T_void *p_buffer, T_word32 size) |
T_void | FileSeek (T_file file, T_word32 position) |
T_sword32 | FileWrite (T_file file, T_void *p_buffer, T_word32 size) |
File IO.
Routines for loading/saving files.
#define MAX_FILES 20 |
Close a previously opened file. Nothing really special here.
file | – file to close. |
FileExist checks to see if a file exists and returns TRUE if it does.
p_filename | – File to check size of |
FileGetSize looks at a given file name and returns the size of that file.
NOTE: This is the WATCOM C/C++ v10.0 specific version.
p_filename | – File to get size of |
FileLoad allocates and reads in a file in one swipe so that the calling routine can just use the file like a memory allocation.
p_filename | – File to load |
p_size | – Indirect reference to the size of the file. |
T_file FileOpen | ( | T_byte8 * | p_filename, |
E_fileMode | mode | ||
) |
Open a file for reading, writing, appending, etc. All files are created unless you request to read. A file handle is returned for all future accesses. Note that a maximum of MAX_FILES is allowed to be opened at a time.
NOTE: Obviously I can't check to see if someone does something stupid to a file they shouldn't be touching, but there is always the possibility.
p_filename | – pointer to the string that holds the real filename. Note that we don't have any particular format in mind. A path name can be included. |
mode | – Different read/write modes. See .H |
FileRead is used to retrieve bytes from a file from the current file position.
NOTE: There is no way to check if the buffer pointer that is passed has enough room for the data is about to be read and may overwrite a bunch of stuff that is valuable (including the OS).
file | – handle of file to read from. |
p_buffer | – Pointer to buffer to read bytes into. |
size | – number of bytes to read. |
Perhaps one of the most useful file routines is the file seek function. Just provide the file to seek into and you will be position at the point you requested.
NOTE: Doesn't check to see if you stayed inside the file bounds. This is not really a problem for writing, but can be a big problem for reading.
file | – File to seek into |
position | – position to seek from the beginning. A position of 0 is the very first byte. |
Use FileWrite to store bytes at the current file position. When the writing is done, the current file position will be at the next byte after all of the writing.
NOTE: This routine doesn't check to see if we have a file handle that is for writing. You could get some weird errors if this happens.
file | – handle of file to write to. |
p_buffer | – Pointer to buffer to write bytes from. |
size | – number of bytes to write. |