build system revision
[vg.git] / vg_io.h
1 /* Copyright (C) 2021-2024 Harry Godden (hgn) - All Rights Reserved */
2
3 #pragma once
4 #include "vg_platform.h"
5 #include "vg_log.h"
6 #include "vg_mem.h"
7
8 typedef struct vg_dir vg_dir;
9 #ifndef _WIN32
10 #include <dirent.h>
11 struct vg_dir{
12 DIR *h;
13 struct dirent *data;
14 u32 index;
15 };
16 #else
17 #include <windows.h>
18 #include <fileapi.h>
19 struct vg_dir{
20 HANDLE h;
21 WIN32_FIND_DATA data;
22 u32 index;
23 };
24 #endif
25
26 enum vg_entry_type{
27 k_vg_entry_type_unknown,
28 k_vg_entry_type_file,
29 k_vg_entry_type_dir
30 };
31
32 int vg_dir_open( vg_dir *dir, const char *name );
33 const char *vg_dir_entry_name( vg_dir *dir );
34 int vg_dirskip( vg_dir *dir );
35 int vg_dir_next_entry( vg_dir *dir );
36 enum vg_entry_type vg_dir_entry_type( vg_dir *dir );
37 void vg_dir_close( vg_dir *dir );
38 void vg_file_print_invalid( FILE *fp );
39
40 /*
41 * File I/O
42 */
43
44 /* read entire binary file */
45 void *vg_file_read( void *lin_alloc, const char *path, u32 *size );
46
47 /* read entire file and append a null on the end */
48 char *vg_file_read_text( void *lin_alloc, const char *path, u32 *sz );
49
50 int vg_asset_write( const char *path, void *data, i64 size );
51 int vg_file_copy( const char *src, const char *dst, void *lin_alloc );
52 const char *vg_path_filename( const char *path );