X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_io.h;h=640ceaea12dd0397320c9cb143f1527b02641460;hb=ffd724233b7a3cb89d0d5d253ba4c475d87c76e2;hp=93525446094aa6a9ee3dac9ff9e0fad914b4673f;hpb=2026f6fe648696888762c5b10210191748a6c9de;p=vg.git diff --git a/vg_io.h b/vg_io.h index 9352544..640ceae 100644 --- a/vg_io.h +++ b/vg_io.h @@ -10,11 +10,24 @@ #include #include + #define _TINYDIR_MALLOC(_size) vg_linear_alloc( vg_mem.scratch, _size ) #define _TINYDIR_FREE(_size) #include "submodules/tinydir/tinydir.h" +#include +VG_STATIC int vg_mkdir( const char *path ) +{ + if( mkdir( path, S_IRWXU|S_IRWXG|S_IWOTH|S_IXOTH ) ){ + vg_error( "Failed to create directory: %s\n", path ); + return 0; + } + else{ + return 1; + } +} + /* * File I/O */ @@ -71,7 +84,6 @@ VG_STATIC void *vg_file_read( void *lin_alloc, const char *path, u32 *size ) fclose( f ); *size = (u32)current; - return buffer; } else{ @@ -110,4 +122,27 @@ 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 ) +{ + vg_info( "vg_file_copy( %s -> %s )\n", src, dst ); + u32 size; + void *data = vg_file_read( lin_alloc, src, &size ); + return vg_asset_write( dst, data, size ); +} + +VG_STATIC const char *vg_path_filename( const char *path ) +{ + const char *base = path; + + for( int i=0; i<1024; i++ ){ + if( path[i] == '\0' ) break; + if( path[i] == '/' ){ + base = path+i+1; + } + } + + return base; +} + #endif /* VG_IO_H */