2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 01:45:19 +01:00

filesystem: add new API function LoadFileMalloc that returns a pointer that can be freed using standard free()

This commit is contained in:
Alibek Omarov 2024-02-07 05:06:05 +03:00
parent bb03e2597c
commit 636a2228f6
3 changed files with 10 additions and 1 deletions

View File

@ -2490,6 +2490,10 @@ static byte *FS_LoadFile_( const char *path, fs_offset_t *filesizeptr, const qbo
return buf; 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 ) 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, (void *)FS_MountArchive_Fullpath,
FS_GetFullDiskPath, FS_GetFullDiskPath,
FS_LoadFileMalloc,
}; };
int EXPORT GetFSAPI( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *engfuncs ); int EXPORT GetFSAPI( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *engfuncs );

View File

@ -196,6 +196,9 @@ typedef struct fs_api_t
void *(*MountArchive_Fullpath)( const char *path, int flags ); void *(*MountArchive_Fullpath)( const char *path, int flags );
qboolean (*GetFullDiskPath)( char *buffer, size_t size, const char *name, qboolean gamedironly ); 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; } fs_api_t;
typedef struct fs_interface_t typedef struct fs_interface_t

View File

@ -103,7 +103,7 @@ typedef struct searchpath_s
int (*pfnFileTime)( struct searchpath_s *search, const char *filename ); int (*pfnFileTime)( struct searchpath_s *search, const char *filename );
int (*pfnFindFile)( struct searchpath_s *search, const char *path, char *fixedname, size_t len ); 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 ); 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; } searchpath_t;
typedef searchpath_t *(*FS_ADDARCHIVE_FULLPATH)( const char *path, int flags ); 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 // file buffer ops
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); 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 ); byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr );
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len ); qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len );