A.6 General File Handling

A.6.1 OpenFile()

Usage

int OpenFile(char *Filename, short WriteTo);

Purpose

Opens a file for reading or writing.

Inputs

Filename, (path)name of the file to read or write.

WriteTo, 1 to create and open for writing, 0 to open for reading.

Outputs

Returns DOS handle for opened file, or -1 on error.

A.6.2 CloseFile()

Usage

void CloseFile(int Handle);

Purpose

Closes a file opened by OpenFile().

Inputs

Handle, DOS handle of the file to close.

Outputs

None

A.6.3 ReadFile()

Usage

int ReadFile(int Handle, void *Buffer, unsigned int Count);

Purpose

Reads from a file.

Inputs

Handle, DOS handle of the file to read from.

Buffer, starting address of the buffer to read into.

Count, (maximum) number of bytes to read into buffer.

Outputs

Returns number of bytes actually read from the file into the buffer.

A.6.4 ReadFile_Sel()

Usage

int ReadFile_Sel(int Handle, short BufSel, void *Buffer, unsigned int Count);

Inputs

Handle, DOS handle of the file to read from.

BufSel, selector of memory segment in which buffer resides.

Buffer, starting address (within the memory segment selected by BufSel) of the buffer to read into.

Count, (maximum) number of bytes to read into buffer.

Outputs

Returns number of bytes actually read from the file into the buffer.

A.6.5 WriteFile()

Usage

int WriteFile(int Handle, void *Buffer, unsigned int Count);

Purpose

Writes into a file.

Inputs

Handle, DOS handle of the file to write into.

Buffer, starting address of the buffer to read from.

Count, (maximum) number of bytes to write into the file.

Outputs

Returns number of bytes actually written into the file from the buffer.

A.6.6 WriteFile_Sel()

Usage

int WriteFile_Sel(int Handle, short BufSel, void *Buffer, unsigned int Count);

Inputs

Handle, DOS handle of the file to write into.

BufSel, selector of memory segment in which buffer resides.

Buffer, starting address (within the memory segment selected by BufSel) of the buffer to read from.

Count, (maximum) number of bytes to write into the file.

Outputs

Returns number of bytes actually written into the file from the buffer.

A.6.7 SeekFile()

Usage

int SeekFile(int Handle, int Count, short From);

Purpose

Moves current file position (the file position is where reading or writing operations start at).

Inputs

Handle, DOS handle of the file to seek within.

Count, number of bytes to seek from position specified by From. May be negative to seek backwards in the file.

From, file position to seek from: 0=start of file, 1=current file position, 2=end of file

Outputs

Returns new file position (in bytes, from start of file), or -1 on error.