19d468b8e1ce39634cdbe31dcdac7e1447c6a363
1 /* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
7 #include "vg_platform.h"
13 static i64
vg_file_size( FILE *fileptr
)
15 fseek( fileptr
, 0, SEEK_END
);
16 i64 fsize
= ftell( fileptr
);
17 fseek( fileptr
, 0, SEEK_SET
);
22 static void *vg_disk_open_read( const char *path
, int reserve_end
, i64
*size
)
24 FILE *f
= fopen( path
, "rb" );
27 i64 fsize
= vg_file_size( f
);
28 void *buf
= malloc( fsize
+ reserve_end
);
32 /* Invalid / corrupt read */
33 if( fread( buf
, 1, fsize
, f
) != fsize
)
51 static char *vg_disk_load_text( const char *path
, i64
*size
)
56 if( (buf
= (char *)vg_disk_open_read( path
, 1, &fsize
)) )
67 static void *vg_asset_read_s( const char *path
, i64
*size
)
69 return vg_disk_open_read( path
, 0, size
);
72 static void *vg_asset_read( const char *path
)
75 return vg_disk_open_read( path
, 0, &size
);
78 static char *vg_textasset_read_s( const char *path
, i64
*size
)
80 return vg_disk_load_text( path
, size
);
83 static char *vg_textasset_read( const char *name
)
86 return vg_disk_load_text( name
, &size
);
89 static int vg_asset_write( const char *path
, void *data
, i64 size
)
91 FILE *f
= fopen( path
, "wb" );
94 fwrite( data
, size
, 1, f
);