OpenFile Function

Opens or creates a file, returning a File handle on success. File handles should be closed with delete or CloseHandle().

The open mode may be one of the following strings: "r": Open an existing file for reading. "w": Create a file for writing, or truncate (delete the contents of) an existing file and then open it for writing. "a": Create a file for writing, or open an existing file such that writes will be appended to the end. "r+": Open an existing file for both reading and writing. "w+": Create a file for reading and writing, or truncate an existing file and then open it for reading and writing. "a+": Create a file for both reading and writing, or open an existing file such that writes will be appended to the end.

The open mode may also contain an additional character after "r", "w", or "a", but before any "+" sign. This character may be "b" (indicating binary mode) or "t" (indicating text mode). By default, "text" mode is implied. On Linux and Mac, this has no distinction from binary mode. On Windows, it causes the '\n' character (0xA) to be written as "\r\n" (0xD, 0xA).

Example: "rb" opens a binary file for reading; "at" opens a text file for appending.

File OpenFile(const char[] file, const char[] mode, bool use_valve_fs, const char[] valve_path_id)

Parameters

const char[] file

File to open.

const char[] mode

Open mode.

bool use_valve_fs

If true, the Valve file system will be used instead. This can be used to find files existing in valve search paths, rather than solely files existing directly in the gamedir.

const char[] valve_path_id

If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.

Return Value

A File handle, or null if the file could not be opened.