1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
4 // ===========================================================================================================
7 #define KRED "\x1B[31m"
8 #define KGRN "\x1B[32m"
9 #define KYEL "\x1B[33m"
10 #define KBLU "\x1B[34m"
11 #define KMAG "\x1B[35m"
12 #define KCYN "\x1B[36m"
13 #define KWHT "\x1B[37m"
15 #define VG_LOG_WRITE( FILE, PREFIX ) \
16 fprintf( FILE, PREFIX ); \
18 va_start( args, fmt ); \
19 vfprintf( FILE, fmt, args ); \
21 fprintf( FILE, KNRM );
23 void vg_success( const char *fmt
, ... ) { VG_LOG_WRITE( stdout
, (KGRN
"success" KWHT
"| " KGRN
) ); }
24 void vg_info( const char *fmt
, ... ) { VG_LOG_WRITE( stdout
, (KNRM
" info" KWHT
"| " KNRM
) ); }
25 void vg_warn( const char *fmt
, ... ) { VG_LOG_WRITE( stdout
, (KYEL
" warn" KWHT
"| " KYEL
) ); }
26 void vg_error( const char *fmt
, ... ) { VG_LOG_WRITE( stderr
, (KRED
" error" KWHT
"| " KRED
) ); }
29 // ===========================================================================================================
31 i64
vg_file_size( FILE *fileptr
)
33 fseek( fileptr
, 0, SEEK_END
);
34 i64 fsize
= ftell( fileptr
);
35 fseek( fileptr
, 0, SEEK_SET
);
40 void *vg_disk_open_read( const char *path
, int const reserve_end
, i64
*size
)
42 FILE *f
= fopen( path
, "rb" );
45 i64 fsize
= vg_file_size( f
);
46 void *buf
= malloc( fsize
+ reserve_end
);
50 // Invalid / corrupt read
51 if( fread( buf
, 1, fsize
, f
) != fsize
)
69 char *vg_disk_load_text( const char *path
, i64
*size
)
74 if( (buf
= vg_disk_open_read( path
, 1, &fsize
)) )
85 void *vg_asset_read_s( const char *path
, i64
*size
)
87 return vg_disk_open_read( path
, 0, size
);
90 void *vg_asset_read( const char *path
)
93 return vg_disk_open_read( path
, 0, &size
);
96 char *vg_textasset_read_s( const char *path
, i64
*size
)
98 return vg_disk_load_text( path
, size
);
101 char *vg_textasset_read( const char *name
)
104 return vg_disk_load_text( name
, &size
);