Fixed leaky imports, modified log stuff

This commit is contained in:
Krzosa Karol
2022-10-11 10:20:18 +02:00
parent 977a62d5ae
commit 4004b8b8d3
8 changed files with 67 additions and 41 deletions

View File

@@ -21,14 +21,14 @@ os_write_file(String filename, String filecontent){
}
function String
os_read_file(Allocator *a, String name){
os_read_file(Arena *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 *)exp_alloc(a, result.len + 1);
result.str = (U8 *)arena_push_size(a, result.len + 1);
fread(result.str, result.len, 1, f);
fclose(f);
result.str[result.len] = 0;
@@ -38,7 +38,7 @@ os_read_file(Allocator *a, String name){
}
function String
os_get_exe_dir(Allocator *a){
os_get_exe_dir(Arena *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(Allocator *a){
}
function String
os_get_absolute_path(Allocator *a, String path){
os_get_absolute_path(Arena *a, String path){
assert(path.str[path.len] == 0);
char buffer[PATH_MAX] = {};
realpath((char *)path.str, buffer);
@@ -73,14 +73,14 @@ os_does_file_exist(String path){
}
function String
os_get_working_dir(Allocator *allocator){
char *buffer = exp_alloc_array(allocator, char, PATH_MAX);
os_get_working_dir(Arena *allocator){
char *buffer = arena_push_array(allocator, char, PATH_MAX);
char *result = getcwd(buffer, PATH_MAX);
return string_from_cstring(result);
}
function Array<OS_File_Info>
os_list_dir(Allocator *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
os_list_dir(Arena *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
Scratch scratch(a);
Array<String> dirs_to_read = {scratch};
dirs_to_read.add(dir);
@@ -120,7 +120,7 @@ os_list_dir(Allocator *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
closedir(d);
}
else{
log_info("ERROR Failed to read dir: %Q, errno: %s\n", *it, strerror(errno));
log_info("ERROR Failed to read dir: %Q, errno: %s", *it, strerror(errno));
}
}