The checked file and memory routines of the PC port.
More...
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
Go to the source code of this file.
|
| struct | GameFile |
| | A file opened by the checked read or write routines. More...
|
|
| typedef struct GameFile | GameFile |
| | A file opened by the checked read or write routines.
|
|
| void | ReadEntireFile (void *buffer, const char *path, int size) |
| | Read size bytes from path into buffer, or the entire file when size is negative.
|
| void * | CHK_AllocateMemory (size_t nSize, const char *szCaller) |
| | Allocate memory, ending the process when none is left.
|
| void * | CHK_ReAllocateMemory (void *pMemory, size_t nSize, const char *szCaller) |
| | Resize an allocation, ending the process on failure for a nonzero size.
|
| int | CHK_FileExists (const char *pszPath) |
| | Whether a file can be opened for reading.
|
| GameFile * | CHK_FReadOpen (const char *pszPath) |
| | Open a file for reading in binary mode.
|
| GameFile * | CHK_FWriteOpen (const char *path, const char *mode) |
| | Open a file in the requested mode, reporting a failure before ending the process.
|
| void | CHK_FPutS (const char *text, GameFile *file) |
| | Write a string, reporting a failure before ending the process.
|
| bool | FCHK_FRead (void *pBuffer, size_t nSize, size_t nCount, GameFile *pFile) |
| | Read items of a file.
|
| void * | CHK_FRead (void *pBuffer, size_t nSize, size_t nCount, GameFile *pFile) |
| | Read items of a file.
|
| long | GetFileLength (GameFile *pFile) |
| | The length of a file, leaving its position unchanged.
|
| char * | FileReadLine (char *pszLine, int nSize, GameFile *pFile) |
| | Read a line of a file.
|
| void | CHK_FClose (GameFile *pFile) |
| | Close a file and free it.
|
|
| int | g_bVerboseFileTrace |
| | Whether the routines write each file they open or close to the debugger.
|
The checked file and memory routines of the PC port.
A failure is written to the debugger and ends the process.
◆ GameFile
| typedef struct GameFile GameFile |
A file opened by the checked read or write routines.
◆ ReadEntireFile()
| void ReadEntireFile |
( |
void * | buffer, |
|
|
const char * | path, |
|
|
int | size ) |
Read size bytes from path into buffer, or the entire file when size is negative.
A missing file ends the game.
- Parameters
-
| buffer | Destination with enough space for the requested data. |
| path | Source file path. |
| size | Bytes to read, or a negative value for the file's full length. |
- Ghidra address:
- BRD3D: 0x100378b0
- Ghidra address:
- BRGlide: 0x10030f50
◆ CHK_AllocateMemory()
| void * CHK_AllocateMemory |
( |
size_t | nSize, |
|
|
const char * | szCaller ) |
Allocate memory, ending the process when none is left.
- Parameters
-
| nSize | The size in bytes. |
| szCaller | What the memory is for, written to the debugger when the allocation fails. |
- Returns
- The memory, or NULL for a size of 0.
- Ghidra address:
- BRD3D: 0x10003390
- Ghidra address:
- BRGlide: 0x100036f0
- Ghidra address:
- BRally: 0x004010c0
- Ghidra address:
- SetVideo: 0x00401470
◆ CHK_ReAllocateMemory()
| void * CHK_ReAllocateMemory |
( |
void * | pMemory, |
|
|
size_t | nSize, |
|
|
const char * | szCaller ) |
Resize an allocation, ending the process on failure for a nonzero size.
- Parameters
-
| pMemory | Existing allocation, or NULL to allocate. |
| nSize | Requested size in bytes. |
| szCaller | Description written to the debugger on failure. |
- Returns
- Resized memory, or NULL when
nSize is zero.
- Ghidra address:
- BRD3D: 0x100033f0
- Ghidra address:
- BRGlide: 0x10003760
◆ CHK_FileExists()
| int CHK_FileExists |
( |
const char * | pszPath | ) |
|
Whether a file can be opened for reading.
- Parameters
-
| pszPath | The path of the file. |
- Returns
- Whether the file opened.
- Ghidra address:
- BRD3D: 0x10003320
- Ghidra address:
- BRGlide: 0x10003680
- Ghidra address:
- BRally: 0x00401050
- Ghidra address:
- SetVideo: 0x00401400
◆ CHK_FReadOpen()
| GameFile * CHK_FReadOpen |
( |
const char * | pszPath | ) |
|
Open a file for reading in binary mode.
A file that does not open is reported in c:\RallyError.txt and to the debugger, and ends the process.
- Parameters
-
| pszPath | The path of the file. |
- Returns
- The open file.
- Ghidra address:
- BRD3D: 0x10002fe0
- Ghidra address:
- BRGlide: 0x10003320
- Ghidra address:
- SetVideo: 0x00401050
◆ CHK_FWriteOpen()
| GameFile * CHK_FWriteOpen |
( |
const char * | path, |
|
|
const char * | mode ) |
Open a file in the requested mode, reporting a failure before ending the process.
- Ghidra address:
- SetVideo: 0x00401230
◆ CHK_FPutS()
| void CHK_FPutS |
( |
const char * | text, |
|
|
GameFile * | file ) |
Write a string, reporting a failure before ending the process.
- Ghidra address:
- SetVideo: 0x00401310
◆ FCHK_FRead()
| bool FCHK_FRead |
( |
void * | pBuffer, |
|
|
size_t | nSize, |
|
|
size_t | nCount, |
|
|
GameFile * | pFile ) |
Read items of a file.
A read that ends part way through ends the process.
- Parameters
-
| pBuffer | The buffer that receives the items. |
| nSize | The size of an item. |
| nCount | The number of items. |
| pFile | The open file. |
- Returns
- false when nothing was read at the end of the file, and true otherwise.
- Ghidra address:
- BRD3D: 0x100030e0
- Ghidra address:
- BRGlide: 0x10003430
◆ CHK_FRead()
| void * CHK_FRead |
( |
void * | pBuffer, |
|
|
size_t | nSize, |
|
|
size_t | nCount, |
|
|
GameFile * | pFile ) |
Read items of a file.
A read at the end of the file, or one that ends part way through, ends the process.
- Parameters
-
| pBuffer | The buffer that receives the items. |
| nSize | The size of an item. |
| nCount | The number of items. |
| pFile | The open file. |
- Returns
- The buffer.
- Ghidra address:
- BRD3D: 0x10003170
- Ghidra address:
- BRGlide: 0x100034c0
◆ GetFileLength()
The length of a file, leaving its position unchanged.
- Parameters
-
- Returns
- The length in bytes.
- Ghidra address:
- BRD3D: 0x10002f90
- Ghidra address:
- BRGlide: 0x100032d0
◆ FileReadLine()
| char * FileReadLine |
( |
char * | pszLine, |
|
|
int | nSize, |
|
|
GameFile * | pFile ) |
Read a line of a file.
A carriage return, a line feed, or both end the line, and the line is stored with a line feed. A line that fills the buffer is stored without a terminator.
- Parameters
-
| pszLine | The buffer that receives the line. |
| nSize | The size of the buffer. |
| pFile | The open file. |
- Returns
- The byte after the terminator of the line, the end of a full buffer, or NULL at the end of the file.
- Ghidra address:
- BRD3D: 0x100031e0
- Ghidra address:
- BRGlide: 0x10003530
- Ghidra address:
- SetVideo: 0x00401150
◆ CHK_FClose()
Close a file and free it.
A file that does not close ends the process.
- Parameters
-
- Ghidra address:
- BRD3D: 0x10003290
- Ghidra address:
- BRGlide: 0x100035e0
- Ghidra address:
- SetVideo: 0x00401370
◆ g_bVerboseFileTrace
Whether the routines write each file they open or close to the debugger.
- Ghidra address:
- BRD3D: 0x10220ce0
- Ghidra address:
- BRGlide: 0x1021c810
- Ghidra address:
- BRally: 0x00403218
- Ghidra address:
- SetVideo: 0x0040e000