kiba-engine
filesystem.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <kiba/defines.h>
9 
15 typedef enum file_modes {
23 
25 typedef struct file_handle {
27  void *handle;
31  b8 binary;
35 
44 KB_API b8 filesystem_exists(const char *path);
45 
46 KB_API b8 filesystem_open(file_handle *file, const char *path, b8 binary, file_modes modes);
47 
48 KB_API void filesystem_close(file_handle *file);
49 
50 KB_API b8 filesystem_size(file_handle *file, usize *size);
51 
52 // TODO use strings for string related stuff maybe??
53 
54 KB_API b8 filesystem_read(file_handle *file, usize size, void *out, usize *bytes_read);
55 
56 KB_API b8 filesystem_read_line(file_handle *file, usize max_size, char *out, usize *chars_read);
57 
58 KB_API b8 filesystem_read_all(file_handle *file, usize max_size, void *out, usize *bytes_read);
59 
60 KB_API b8 filesystem_read_all_text(file_handle *file, usize max_size, char *out, usize *chars_read);
61 
62 KB_API b8 filesystem_write(file_handle *file, usize size, const void *data, usize *bytes_written);
63 
64 KB_API b8 filesystem_write_line(file_handle *file, usize size, const char *data, usize *chars_written);
Global typedefs and macros.
file_modes
The modes a file can be opened in.
Definition: filesystem.h:15
@ FILE_MODE_WRITE
Needed to be able to write to a file.
Definition: filesystem.h:19
@ FILE_MODE_READ
Needed to be able to read from a file.
Definition: filesystem.h:17
@ FILE_MODE_APPEND
Needed if the file should not be truncated when opened for writing.
Definition: filesystem.h:21
struct file_handle file_handle
Handle for a file.
KB_API b8 filesystem_exists(const char *path)
Check if a given path exists.
Definition: filesystem.c:16
Handle for a file.
Definition: filesystem.h:25
b8 is_valid
Indicates if the file handle is valid.
Definition: filesystem.h:29
file_modes modes
Contains the modes that were used to open the file.
Definition: filesystem.h:33
b8 binary
Indicates if the file was opened in binary mode as opposed to text mode.
Definition: filesystem.h:31
void * handle
Platform specific handle to the actual file.
Definition: filesystem.h:27