diff options
| author | day <day@national.shitposting.agency> | 2026-03-14 05:21:43 +0100 |
|---|---|---|
| committer | day <day@national.shitposting.agency> | 2026-03-14 05:21:43 +0100 |
| commit | c2a4f7c2e6e4651dda6350a80a57e177f5ff2f55 (patch) | |
| tree | b5cd91a753257e026da0b2e3bc680f7f29ece59d /src/util/file.h | |
| parent | 59ca7ecafca84fa62ee8d54d0e48521b7e4c0a95 (diff) | |
starting obj parsing
Diffstat (limited to 'src/util/file.h')
| -rw-r--r-- | src/util/file.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/util/file.h b/src/util/file.h index e19a390..7e4d413 100644 --- a/src/util/file.h +++ b/src/util/file.h @@ -8,7 +8,7 @@ #include "typedef.h" #include "allocator.h" -inline void* file_read( const char* file ) { +inline void* file_read( const char* file, U64* size = nullptr ) { FILE* f = fopen( file, "rb" ); if( !f ) return 0; @@ -16,15 +16,16 @@ inline void* file_read( const char* file ) { defer( fclose( f ) ); fseek( f, 0, SEEK_END ); - U64 size = ftell( f ); + U64 fsize = ftell( f ); rewind( f ); - if( !size ) + if( !fsize ) return 0; - void* block = malloc( size + 1 ); - fread( block, size, 1, f ); + void* block = malloc( fsize + 1 ); + fread( block, fsize, 1, f ); - ( (U8*)block )[size] = 0; + ( (U8*)block )[fsize] = 0; + if ( size ) *size = fsize; return block; } |
