yabadabadoo
[vg.git] / src / vg / vg_io.h
index c78930075c135fac28ec6565b95e1dcbdeda8b12..b5440ec201be29fd95a234054efd1e594819e16b 100644 (file)
@@ -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;
 }