#include <stdio.h>
#include <errno.h>
+#define _TINYDIR_MALLOC(_size) vg_linear_alloc( vg_mem.scratch, _size )
+#define _TINYDIR_FREE(_size)
+
+#include "submodules/tinydir/tinydir.h"
+
/*
* File I/O
*/
VG_STATIC void vg_file_print_invalid( FILE *fp )
{
- if( feof( fp ))
- {
+ if( feof( fp )) {
vg_error( "mdl_open: header too short\n" );
}
- else
- {
+ else{
if( ferror( fp ))
vg_error( "mdl_open: %s\n", strerror(errno) );
else
VG_STATIC void *vg_file_read( void *lin_alloc, const char *path, u32 *size )
{
FILE *f = fopen( path, "rb" );
- if( f )
- {
+ if( f ){
void *buffer = vg_linear_alloc( lin_alloc, 0 );
u64 current = 0;
/* read in chunks */
- for( u32 i=0; 1; i++ )
- {
+ for( u32 i=0; 1; i++ ){
buffer = vg_linear_extend( lin_alloc, buffer, VG_FILE_IO_CHUNK_SIZE );
u64 l = fread( buffer + current, 1, VG_FILE_IO_CHUNK_SIZE, f );
current += l;
- if( l != VG_FILE_IO_CHUNK_SIZE )
- {
- if( feof( f ) )
- {
+ if( l != VG_FILE_IO_CHUNK_SIZE ){
+ if( feof( f ) ){
break;
}
- else
- {
- if( ferror( f ) )
- {
+ else{
+ if( ferror( f ) ){
fclose(f);
- vg_fatal_exit_loop( "read error" );
+ vg_fatal_error( "read error" );
}
- else
- {
+ else{
fclose(f);
- vg_fatal_exit_loop( "unknown error codition" );
+ vg_fatal_error( "unknown error codition" );
}
}
}
}
- buffer = vg_linear_resize( lin_alloc, buffer, current );
+ buffer = vg_linear_resize( lin_alloc, buffer, vg_align8(current) );
fclose( f );
*size = (u32)current;
return buffer;
}
- else
- {
+ else{
vg_error( "vg_disk_open_read: %s\n", strerror(errno) );
return NULL;
}
}
-VG_STATIC int vg_asset_write( const char *path, void *data, i64 size )
-{
+VG_STATIC int vg_asset_write( const char *path, void *data, i64 size ){
FILE *f = fopen( path, "wb" );
- if( f )
- {
+ if( f ){
fwrite( data, size, 1, f );
fclose( f );
return 1;
}
- else
- {
+ else{
return 0;
}
}