Somehow we compiling and not crashing
This commit is contained in:
43
os_unix.cpp
43
os_unix.cpp
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user