Working on simplifying configurable allocation scheme

This commit is contained in:
Krzosa Karol
2023-01-01 12:40:58 +01:00
parent 8c0a8bf72b
commit c5539276ae
18 changed files with 169 additions and 347 deletions

View File

@@ -21,14 +21,14 @@ os_write_file(String filename, String filecontent){
}
CORE_Static String
os_read_file(Arena *a, String name){
os_read_file(Alloator *a, String name){
String result = {0};
FILE *f = fopen((char *)name.str, "rb");
if(f){
fseek(f, 0, SEEK_END);
result.len = ftell(f);
fseek(f, 0, SEEK_SET);
result.str = (U8 *)arena_push_size(a, result.len + 1);
result.str = (U8 *)allocate_size(a, result.len + 1, false);
fread(result.str, result.len, 1, f);
fclose(f);
result.str[result.len] = 0;
@@ -38,7 +38,7 @@ os_read_file(Arena *a, String name){
}
CORE_Static String
os_get_exe_dir(Arena *a){
os_get_exe_dir(Allocator *a){
char buffer[PATH_MAX] = {};
if (readlink("/proc/self/exe", buffer, PATH_MAX) == -1) {
log_info("Failed to retrieve the path of the executable, the method used is fetching /proc/self/exe, very likely you are using an OS that doesn't follow this convention and as such it is currently not supported");
@@ -52,7 +52,7 @@ os_get_exe_dir(Arena *a){
}
CORE_Static String
os_get_absolute_path(Arena *a, String path){
os_get_absolute_path(Allocator *a, String path){
assert(path.str[path.len] == 0);
char buffer[PATH_MAX] = {};
realpath((char *)path.str, buffer);
@@ -73,15 +73,15 @@ os_does_file_exist(String path){
}
CORE_Static String
os_get_working_dir(Arena *allocator){
char *buffer = arena_push_array(allocator, char, PATH_MAX);
os_get_working_dir(Allocator *allocator){
char *buffer = allocate_array(allocator, char, PATH_MAX, false);
char *result = getcwd(buffer, PATH_MAX);
return string_from_cstring(result);
}
CORE_Static Array<OS_File_Info>
os_list_dir(Arena *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
Scratch scratch(a);
os_list_dir(Scratch_Arena *scratch, Allocator *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
Scratch_Scope _scope(scratch);
Array<String> dirs_to_read = {scratch};
dirs_to_read.add(dir);