diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index 7a96be8c..19925792 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -18,6 +18,7 @@ GNU General Public License for more details. #include "common.h" #include "library.h" +#include "platform/platform.h" fs_api_t g_fsapi; fs_globals_t *FI; @@ -51,6 +52,8 @@ static fs_interface_t fs_memfuncs = _Mem_Alloc, _Mem_Realloc, _Mem_Free, + + Platform_GetNativeObject, }; static void FS_UnloadProgs( void ) diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index d2fa1a04..21e0b43f 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -1277,33 +1277,34 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll return true; } -poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline ) +static poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline ) { return (poolhandle_t)0xDEADC0DE; } -void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline ) +static void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline ) { // stub } -void* _Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) +static void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) { - if( clear ) return calloc( 1, size ); - return malloc( size ); + void *ptr = malloc( size ); + if( clear ) memset( ptr, 0, size ); + return ptr; } -void* _Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) +static void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) { return realloc( memptr, size ); } -void _Mem_Free( void *data, const char *filename, int fileline ) +static void _Mem_Free( void *data, const char *filename, int fileline ) { free( data ); } -void _Con_Printf( const char *fmt, ... ) +static void _Con_Printf( const char *fmt, ... ) { va_list ap; @@ -1312,7 +1313,7 @@ void _Con_Printf( const char *fmt, ... ) va_end( ap ); } -void _Sys_Error( const char *fmt, ... ) +static void _Sys_Error( const char *fmt, ... ) { va_list ap; @@ -1323,6 +1324,10 @@ void _Sys_Error( const char *fmt, ... ) exit( 1 ); } +static void *_Platform_GetNativeObject_stub( const char *object ) +{ + return NULL; +} /* ================ @@ -2738,7 +2743,8 @@ fs_interface_t g_engfuncs = _Mem_FreePool, _Mem_Alloc, _Mem_Realloc, - _Mem_Free + _Mem_Free, + _Platform_GetNativeObject_stub }; static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs ) @@ -2780,6 +2786,12 @@ static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs ) Con_Reportf( "filesystem_stdio: custom memory allocation functions found\n" ); } + if( engfuncs->_Platform_GetNativeObject ) + { + g_engfuncs._Platform_GetNativeObject = engfuncs->_Platform_GetNativeObject; + Con_Reportf( "filesystem_stdio: custom platform-specific functions found\n" ); + } + return true; } diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index 0b46f9af..81073ea8 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -204,6 +204,9 @@ typedef struct fs_interface_t void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ); void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ); void (*_Mem_Free)( void *data, const char *filename, int fileline ); + + // platform + void *(*_Platform_GetNativeObject)( const char *object ); } fs_interface_t; typedef int (*FSAPI)( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *interface ); diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 5abd6c34..8dd0bd78 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -116,6 +116,7 @@ extern fs_api_t g_api; #define Con_DPrintf (*g_engfuncs._Con_DPrintf) #define Con_Reportf (*g_engfuncs._Con_Reportf) #define Sys_Error (*g_engfuncs._Sys_Error) +#define Platform_GetNativeObject (*g_engfuncs.Platform_GetNativeObject) // // filesystem.c