To provide a saner file/stream I/O interface for Q3 mods built as QVM bytecode.


Most of the libc stdio.h functions.

For opening as read, line format is auto-detected as much as possible (out of Unix, MacOS, MS-DOS). This is significant for only fgets(), for now.

For writing, no auto-conversion is done -- MS-DOS text format must be explicitly coded as such (e.g. printf("Hello, world\n\r");).


Semantics and syntax are based mostly on the documentation of GNU libc 2.1, which should be available on any GNU system (e.g. GNU/Linux, GNU/HURD, Cygwin32, DJGPP). The BSD libc documentation might suffice, but I'm not certain.


The scanf family of functions is left unimplemented. I really don't like scanf().

Functions related to temporary files (mktemp, et. al) are not implemented.

Read-write mode is impossible in QVM. It can, however, be faked by closing and re-opening with alternating modes.

Write-seek is not implemented. This could be faked by using temporary files and writing back-and-forth, as suggested by Timbo of Tremulous Q3 mod.

Use of errno is inconsistent.

Programming Notes

The source as given has a limit of 40 open files. This can be changed by altering the value of FOPEN_MAX in the .h file. Q3 v1.17 had a limit of 8 simultaneous open files. This limit has probably been lifted in succeeding versions.

You can see vestiges of an attempt at an abstracted device layer in response to the standard file descriptors. Please don't laugh at me.

(2002.03.09) Updated fseek() and using SEEK_* constants. bg_io.c, bg_io.h.
(2001.09.15) Drop-in files into game/ directory. Remember to alter the .q3asm file and your compilation script/batch file to include bg_io(.c): bg_io.c, bg_io.h.
-- PhaethonH (PhaethonH@gmail.com)