From 0637a32655d98c3adb64c3c9fead4b966ae24f36 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 9 Oct 2022 11:05:03 +0200 Subject: [PATCH] Somehow we compiling and not crashing --- build_unix.sh | 2 +- core_main.cpp | 1 + os_unix.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/build_unix.sh b/build_unix.sh index f41d0bc..a5dedc6 100644 --- a/build_unix.sh +++ b/build_unix.sh @@ -1,3 +1,3 @@ #!/bin/bash -clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.ex \ No newline at end of file +clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core \ No newline at end of file diff --git a/core_main.cpp b/core_main.cpp index dd76289..202a47d 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -295,5 +295,6 @@ int main(int argument_count, char **arguments){ compile_file(it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING); } } + log_info("End of program\n"); return 0; } diff --git a/os_unix.cpp b/os_unix.cpp index 4eb70c2..2b4b8f7 100644 --- a/os_unix.cpp +++ b/os_unix.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define POSIX_PATH_MAX_KIND_OF 4096 #define POSIX_PAGE_SIZE 4096 @@ -41,7 +42,12 @@ os_get_exe_dir(Allocator *a){ function String os_get_absolute_path(Allocator *a, String path){ - return ""_s; + char *buffer_out = exp_alloc_array(a, char, POSIX_PATH_MAX_KIND_OF); + assert(path.str[path.len] == 0); + realpath((char *)path.str, buffer_out); + // @memory @todo: If we allocated only 32 bytes here then deallocate rest + + return string_from_cstring(buffer_out); } function B32 @@ -56,6 +62,41 @@ os_get_working_dir(Allocator *allocator){ return string_from_cstring(result); } +function Array +os_list_dir(Allocator *a, String dir, U32 flags = LIST_NO_FLAGS){ + Scratch scratch(a); + Array dirs_to_read = {scratch}; + dirs_to_read.add(dir); + + Array result = {a}; + for(auto it = dirs_to_read.begin(); it != dirs_to_read.end(); it++){ + assert(it->str[it->len] == 0); + dirent *dir; + DIR *d = opendir((char *)it->str); + if(d){ + while ((dir = readdir(d)) != NULL) { + if(dir->d_name[0] == '.'){ + if(dir->d_name[1] == '.'){ + if(dir->d_name[2] == 0) + continue; + } + + if(dir->d_name[1] == 0) + continue; + } + + OS_File_Info entry = {}; + entry.relative_path = string_from_cstring(dir->d_name); + entry.absolute_path = os_get_absolute_path(a, entry.relative_path); + log_info("%Q\n", entry.absolute_path); + } + closedir(d); + } + } + + return result; +} + function U8 * os_advance_commit(OS_Memory *m, size_t *commit_size, size_t page_size) { size_t aligned_up_commit = align_up(*commit_size, page_size);