Amulets & Armor  v1.02
Open Source Game
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Macros | Functions
FILE

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_voidFileLoad (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)
 

Detailed Description

File IO.

Routines for loading/saving files.

See Also
http://www.amuletsandarmor.com/AALicense.txt

Macro Definition Documentation

#define MAX_FILES   20

Function Documentation

T_void FileClose ( T_file  file)

Close a previously opened file. Nothing really special here.

Parameters
file– file to close.
E_Boolean FileExist ( T_byte8 p_filename)

FileExist checks to see if a file exists and returns TRUE if it does.

Parameters
p_filename– File to check size of
Returns
TRUE=file exists, else FALSE
T_word32 FileGetSize ( T_byte8 p_filename)

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.

Parameters
p_filename– File to get size of
Returns
Size of file
T_void* FileLoad ( T_byte8 p_filename,
T_word32 p_size 
)

FileLoad allocates and reads in a file in one swipe so that the calling routine can just use the file like a memory allocation.

Parameters
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.

Parameters
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
Returns
file handle for all future accesses.
T_sword32 FileRead ( T_file  file,
T_void p_buffer,
T_word32  size 
)

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).

Parameters
file– handle of file to read from.
p_buffer– Pointer to buffer to read bytes into.
size– number of bytes to read.
Returns
number of bytes read, or -1 for error.
T_void FileSeek ( T_file  file,
T_word32  position 
)

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.

Parameters
file– File to seek into
position– position to seek from the beginning. A position of 0 is the very first byte.
T_sword32 FileWrite ( T_file  file,
T_void p_buffer,
T_word32  size 
)

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.

Parameters
file– handle of file to write to.
p_buffer– Pointer to buffer to write bytes from.
size– number of bytes to write.
Returns
number of bytes written, or else -1.