diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 39114992..4d42719b 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -2490,6 +2490,10 @@ static byte *FS_LoadFile_( const char *path, fs_offset_t *filesizeptr, const qbo return buf; } +byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ) +{ + return FS_LoadFile_( path, filesizeptr, gamedironly, false ); +} byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ) { @@ -3042,6 +3046,7 @@ fs_api_t g_api = (void *)FS_MountArchive_Fullpath, FS_GetFullDiskPath, + FS_LoadFileMalloc, }; int EXPORT GetFSAPI( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *engfuncs ); diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index 9a312adc..716fb4d6 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -196,6 +196,9 @@ typedef struct fs_api_t void *(*MountArchive_Fullpath)( const char *path, int flags ); qboolean (*GetFullDiskPath)( char *buffer, size_t size, const char *name, qboolean gamedironly ); + + // like LoadFile but returns pointer that can be free'd using standard library function + byte *(*LoadFileMalloc)( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); } fs_api_t; typedef struct fs_interface_t diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 266890e9..8ef42183 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -103,7 +103,7 @@ typedef struct searchpath_s int (*pfnFileTime)( struct searchpath_s *search, const char *filename ); int (*pfnFindFile)( struct searchpath_s *search, const char *path, char *fixedname, size_t len ); void (*pfnSearch)( struct searchpath_s *search, stringlist_t *list, const char *pattern, int caseinsensitive ); - byte *(*pfnLoadFile)( struct searchpath_s *search, const char *path, int pack_ind, fs_offset_t *filesize ); + byte *(*pfnLoadFile)( struct searchpath_s *search, const char *path, int pack_ind, fs_offset_t *filesize, void *( *pfnAlloc )( size_t ), void ( *pfnFree )( void * )); } searchpath_t; typedef searchpath_t *(*FS_ADDARCHIVE_FULLPATH)( const char *path, int flags ); @@ -181,6 +181,7 @@ qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize ); // file buffer ops byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); +byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr ); qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len );