CORE_Static
This commit is contained in:
26
os_linux.cpp
26
os_linux.cpp
@@ -9,7 +9,7 @@
|
||||
|
||||
#define POSIX_PAGE_SIZE 4096
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
os_write_file(String filename, String filecontent){
|
||||
FILE *f = fopen((const char *)filename.str, "w");
|
||||
if(f){
|
||||
@@ -20,7 +20,7 @@ os_write_file(String filename, String filecontent){
|
||||
return false;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
os_read_file(Arena *a, String name){
|
||||
String result = {0};
|
||||
FILE *f = fopen((char *)name.str, "rb");
|
||||
@@ -37,7 +37,7 @@ os_read_file(Arena *a, String name){
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
os_get_exe_dir(Arena *a){
|
||||
char buffer[PATH_MAX] = {};
|
||||
if (readlink("/proc/self/exe", buffer, PATH_MAX) == -1) {
|
||||
@@ -51,7 +51,7 @@ os_get_exe_dir(Arena *a){
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
os_get_absolute_path(Arena *a, String path){
|
||||
assert(path.str[path.len] == 0);
|
||||
char buffer[PATH_MAX] = {};
|
||||
@@ -61,7 +61,7 @@ os_get_absolute_path(Arena *a, String path){
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
os_does_file_exist(String path){
|
||||
B32 result = false;
|
||||
assert(path.str[path.len] == 0);
|
||||
@@ -72,14 +72,14 @@ os_does_file_exist(String path){
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
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>
|
||||
CORE_Static Array<OS_File_Info>
|
||||
os_list_dir(Arena *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
|
||||
Scratch scratch(a);
|
||||
Array<String> dirs_to_read = {scratch};
|
||||
@@ -127,7 +127,7 @@ os_list_dir(Arena *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS){
|
||||
return result;
|
||||
}
|
||||
|
||||
function U8 *
|
||||
CORE_Static 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);
|
||||
size_t to_be_total_commited_size = aligned_up_commit + m->commit;
|
||||
@@ -141,7 +141,7 @@ os_advance_commit(OS_Memory *m, size_t *commit_size, size_t page_size) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function OS_Memory
|
||||
CORE_Static OS_Memory
|
||||
os_reserve(size_t size) {
|
||||
OS_Memory result = {};
|
||||
size_t size_aligned = align_up(size, POSIX_PAGE_SIZE);
|
||||
@@ -153,7 +153,7 @@ os_reserve(size_t size) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
os_commit(OS_Memory *m, size_t commit) {
|
||||
B32 result = false;
|
||||
U8 * pointer = os_advance_commit(m, &commit, POSIX_PAGE_SIZE);
|
||||
@@ -168,7 +168,7 @@ os_commit(OS_Memory *m, size_t commit) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
os_release(OS_Memory *m) {
|
||||
int result = munmap(m->data, m->reserve);
|
||||
assert_message(result == 0, "OS1 POSIX Debug Error: Failed to release virtual memory using munmap");
|
||||
@@ -177,7 +177,7 @@ os_release(OS_Memory *m) {
|
||||
}
|
||||
}
|
||||
|
||||
function U64
|
||||
CORE_Static U64
|
||||
os_get_microseconds() {
|
||||
timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -185,7 +185,7 @@ os_get_microseconds() {
|
||||
return result;
|
||||
}
|
||||
|
||||
function F64
|
||||
CORE_Static F64
|
||||
os_time(){
|
||||
F64 time = (F64)os_get_microseconds();
|
||||
F64 result = time / 1000000.0; // Microseconds to seconds
|
||||
|
||||
Reference in New Issue
Block a user