remove devwindow
[vg.git] / vg_io.h
diff --git a/vg_io.h b/vg_io.h
index 5a37fb3c4ead2d15a4f7564a0bf384c0577e835e..e39c15fa5975b6103e791cb56b41991016c252b6 100644 (file)
--- a/vg_io.h
+++ b/vg_io.h
@@ -144,7 +144,7 @@ static void vg_dir_close( vg_dir *dir ){
   #endif
 #endif
 
-VG_STATIC void vg_file_print_invalid( FILE *fp )
+static void vg_file_print_invalid( FILE *fp )
 {
    if( feof( fp )) {
       vg_error( "mdl_open: header too short\n" );
@@ -159,16 +159,19 @@ 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, u32 *size )
-{
+static void *vg_file_read( void *lin_alloc, const char *path, u32 *size ){
        FILE *f = fopen( path, "rb" );
        if( f ){
-      void *buffer = vg_linear_alloc( lin_alloc, 0 );
+      void *buffer = lin_alloc? vg_linear_alloc( lin_alloc, 0 ):
+                                NULL;
       u64 current = 0;
 
       /* read in chunks */
       for( u32 i=0; 1; i++ ){
-         buffer = vg_linear_extend( lin_alloc, buffer, VG_FILE_IO_CHUNK_SIZE );
+         if( lin_alloc )
+            buffer = vg_linear_extend( lin_alloc,buffer,VG_FILE_IO_CHUNK_SIZE );
+         else 
+            buffer = realloc( buffer, current + VG_FILE_IO_CHUNK_SIZE );
 
          u64 l = fread( buffer + current, 1, VG_FILE_IO_CHUNK_SIZE, f );
          current += l;
@@ -190,21 +193,24 @@ VG_STATIC void *vg_file_read( void *lin_alloc, const char *path, u32 *size )
          }
       }
 
-      buffer = vg_linear_resize( lin_alloc, buffer, vg_align8(current) );
+      if( lin_alloc )
+         buffer = vg_linear_resize( lin_alloc, buffer, vg_align8(current) );
+      else
+         buffer = realloc( buffer, vg_align8(current) );
+
                fclose( f );
 
       *size = (u32)current;
       return buffer;
        }
        else{
-      vg_error( "vg_disk_open_read: %s\n", strerror(errno) );
+      vg_error( "vg_disk_open_read: %s (file: %s)\n", strerror(errno), path );
                return NULL;
        }
 }
 
 /* read entire file and append a null on the end */
-VG_STATIC char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz )
-{
+static char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz ){
    u32 size;
    char *str = vg_file_read( lin_alloc, path, &size );
 
@@ -212,7 +218,11 @@ VG_STATIC char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz )
       return NULL;
 
    /* include null terminator */
-   str = vg_linear_extend( lin_alloc, str, 1 );
+   if( lin_alloc )
+      str = vg_linear_extend( lin_alloc, str, 1 );
+   else
+      str = realloc( str, size+1 );
+
    str[ size ] = '\0';
    *sz = size+1;
 
@@ -220,7 +230,7 @@ VG_STATIC char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz )
 }
 
 
-VG_STATIC int vg_asset_write( const char *path, void *data, i64 size ){
+static int vg_asset_write( const char *path, void *data, i64 size ){
        FILE *f = fopen( path, "wb" );
        if( f ){
                fwrite( data, size, 1, f );
@@ -233,7 +243,7 @@ VG_STATIC int vg_asset_write( const char *path, void *data, i64 size ){
 }
 
 /* TODO: error handling if read fails */
-VG_STATIC int vg_file_copy( const char *src, const char *dst, void *lin_alloc )
+static int vg_file_copy( const char *src, const char *dst, void *lin_alloc )
 {
    vg_info( "vg_file_copy( %s -> %s )\n", src, dst );
    u32 size;
@@ -241,7 +251,7 @@ VG_STATIC int vg_file_copy( const char *src, const char *dst, void *lin_alloc )
    return vg_asset_write( dst, data, size );
 }
 
-VG_STATIC const char *vg_path_filename( const char *path )
+static const char *vg_path_filename( const char *path )
 {
    const char *base = path;