return; // don't execute config.cfg
}
- f = (char *)FS_LoadFile (filename, tempmempool, false, &fsize);
+ f = (char *)FS_LoadFileExtraBuffer (filename, tempmempool, false, 2, &fsize);
if (!f)
{
Con_Printf("couldn't exec %s\n",filename);
if (f[fsize - 1] != '\n')
{
- f = (char *)Mem_Realloc(cbuf_mempool, f, fsize + 2);
f[fsize] = '\n';
f[fsize + 1] = '\0';
++fsize;
Loads full content of a qfile_t and closes it.
Always appends a 0 byte.
+You may specify to allocate extra bytes for the file content buffer, by using the `extrabytes` parameter.
============
*/
-static unsigned char *FS_LoadAndCloseQFile (qfile_t *file, const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
+static unsigned char *FS_LoadAndCloseQFile (qfile_t *file, const char *path, mempool_t *pool, qbool quiet, unsigned long extrabytes, fs_offset_t *filesizepointer)
{
unsigned char *buf = NULL;
fs_offset_t filesize = 0;
return NULL;
}
- buf = (unsigned char *)Mem_Alloc (pool, filesize + 1);
+ buf = (unsigned char *)Mem_Alloc (pool, filesize + 1 + extrabytes);
buf[filesize] = '\0';
FS_Read (file, buf, filesize);
FS_Close (file);
unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
{
qfile_t *file = FS_OpenVirtualFile(path, quiet);
- return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
+ return FS_LoadAndCloseQFile(file, path, pool, quiet, 0, filesizepointer);
+}
+
+/*
+============
+FS_LoadFileExtraBuffer
+
+Filename are relative to the quake directory.
+Always appends a 0 byte, and optionally extra bytes.
+============
+*/
+unsigned char *FS_LoadFileExtraBuffer (const char *path, mempool_t *pool, qbool quiet, unsigned long extrabytes, fs_offset_t *filesizepointer)
+{
+ qfile_t *file = FS_OpenVirtualFile(path, quiet);
+ return FS_LoadAndCloseQFile(file, path, pool, quiet, extrabytes, filesizepointer);
}
unsigned char *FS_SysLoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
{
qfile_t *file = FS_SysOpen(path, "rb", false);
- return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
+ return FS_LoadAndCloseQFile(file, path, pool, quiet, 0, filesizepointer);
}
void FS_FreeSearch(fssearch_t *search);
unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer);
+unsigned char *FS_LoadFileExtraBuffer (const char *path, mempool_t *pool, qbool quiet, unsigned long extrabytes, fs_offset_t *filesizepointer);
unsigned char *FS_SysLoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer);
qbool FS_WriteFileInBlocks (const char *filename, const void *const *data, const fs_offset_t *len, size_t count);
qbool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);