Somehow we compiling and not crashing

This commit is contained in:
Krzosa Karol
2022-10-09 11:05:03 +02:00
parent ed7267a8c8
commit 0637a32655
3 changed files with 44 additions and 2 deletions

View File

@@ -1,3 +1,3 @@
#!/bin/bash
clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.ex
clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core

View File

@@ -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;
}

View File

@@ -2,6 +2,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <dirent.h>
#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_File_Info>
os_list_dir(Allocator *a, String dir, U32 flags = LIST_NO_FLAGS){
Scratch scratch(a);
Array<String> dirs_to_read = {scratch};
dirs_to_read.add(dir);
Array<OS_File_Info> 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);