coastline 0.0.4
Loading...
Searching...
No Matches
fileio.h File Reference

The checked file and memory routines of the PC port. More...

#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
Include dependency graph for fileio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GameFile
 A file opened by the checked read or write routines. More...

Typedefs

typedef struct GameFile GameFile
 A file opened by the checked read or write routines.

Functions

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.

Variables

int g_bVerboseFileTrace
 Whether the routines write each file they open or close to the debugger.

Detailed Description

The checked file and memory routines of the PC port.

A failure is written to the debugger and ends the process.

Typedef Documentation

◆ GameFile

typedef struct GameFile GameFile

A file opened by the checked read or write routines.

Function Documentation

◆ 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
bufferDestination with enough space for the requested data.
pathSource file path.
sizeBytes 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
nSizeThe size in bytes.
szCallerWhat 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
pMemoryExisting allocation, or NULL to allocate.
nSizeRequested size in bytes.
szCallerDescription 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
pszPathThe 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
pszPathThe 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
pBufferThe buffer that receives the items.
nSizeThe size of an item.
nCountThe number of items.
pFileThe 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
pBufferThe buffer that receives the items.
nSizeThe size of an item.
nCountThe number of items.
pFileThe open file.
Returns
The buffer.
Ghidra address:
BRD3D: 0x10003170
Ghidra address:
BRGlide: 0x100034c0

◆ GetFileLength()

long GetFileLength ( GameFile * pFile)

The length of a file, leaving its position unchanged.

Parameters
pFileThe open file.
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
pszLineThe buffer that receives the line.
nSizeThe size of the buffer.
pFileThe 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()

void CHK_FClose ( GameFile * pFile)

Close a file and free it.

A file that does not close ends the process.

Parameters
pFileThe open file.
Ghidra address:
BRD3D: 0x10003290
Ghidra address:
BRGlide: 0x100035e0
Ghidra address:
SetVideo: 0x00401370

Variable Documentation

◆ g_bVerboseFileTrace

int g_bVerboseFileTrace
extern

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