X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=src%2Fvg%2Fvg_io.h;h=b5440ec201be29fd95a234054efd1e594819e16b;hb=3dd767bb10e6fee9cbffeb185d1a9685810c17b5;hp=c78930075c135fac28ec6565b95e1dcbdeda8b12;hpb=5df88af6730a8b9c4ef698070bb729866ed2e597;p=vg.git diff --git a/src/vg/vg_io.h b/src/vg/vg_io.h index c789300..b5440ec 100644 --- a/src/vg/vg_io.h +++ b/src/vg/vg_io.h @@ -33,7 +33,7 @@ VG_STATIC void vg_file_print_invalid( FILE *fp ) } /* read entire binary file */ -VG_STATIC void *vg_file_read( void *lin_alloc, const char *path ) +VG_STATIC void *vg_file_read( void *lin_alloc, const char *path, u32 *size ) { FILE *f = fopen( path, "rb" ); if( f ) @@ -73,6 +73,8 @@ VG_STATIC void *vg_file_read( void *lin_alloc, const char *path ) buffer = vg_linear_resize( lin_alloc, buffer, current ); fclose( f ); + + *size = (u32)current; return buffer; } @@ -84,23 +86,27 @@ VG_STATIC void *vg_file_read( void *lin_alloc, const char *path ) } /* get the size of the file just loaded */ +#if 0 VG_STATIC u32 vg_linear_last_size( void *allocator ); /* ? */ VG_STATIC u32 vg_file_size( void *lin_alloc ) { return vg_linear_last_size( lin_alloc ); } +#endif /* read entire file and append a null on the end */ -VG_STATIC char *vg_file_read_text( void *lin_alloc, const char *path ) +VG_STATIC char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz ) { - char *str = vg_file_read( lin_alloc, path ); + u32 size; + char *str = vg_file_read( lin_alloc, path, &size ); if( !str ) return NULL; /* include null terminator */ str = vg_linear_extend( lin_alloc, str, 1 ); - str[ vg_file_size(lin_alloc) ] = '\0'; + str[ size ] = '\0'; + *sz = size+1; return str; }