Implemented all system library handling functions.

master
Yuval Dolev 2019-12-28 01:54:33 +02:00
parent da150cd322
commit a91158ebf0
2 changed files with 58 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* Mac Objective C layer for 4coder */ /* Mac Objective-C layer for 4coder */
#include "4coder_base_types.h" #include "4coder_base_types.h"
#include "4coder_version.h" #include "4coder_version.h"
@ -54,6 +54,7 @@
#include <libproc.h> // NOTE(yuval): Used for proc_pidpath #include <libproc.h> // NOTE(yuval): Used for proc_pidpath
#include <dirent.h> // NOTE(yuval): Used for opendir, readdir #include <dirent.h> // NOTE(yuval): Used for opendir, readdir
#include <dlfcn.h> // NOTE(yuval): Used for dlopen, dlclose, dlsym
#include <errno.h> // NOTE(yuval): Used for errno #include <errno.h> // NOTE(yuval): Used for errno
#include <fcntl.h> // NOTE(yuval): Used for open #include <fcntl.h> // NOTE(yuval): Used for open
#include <unistd.h> // NOTE(yuval): Used for getcwd, read, write, getpid #include <unistd.h> // NOTE(yuval): Used for getcwd, read, write, getpid
@ -67,6 +68,8 @@
#define global static #define global static
#define external extern "C" #define external extern "C"
////////////////////////////////
@interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate> @interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
@end @end
@ -116,7 +119,7 @@ struct Mac_Vars {
//////////////////////////////// ////////////////////////////////
Mac_Vars mac_vars; global Mac_Vars mac_vars;
global Render_Target target; global Render_Target target;
//////////////////////////////// ////////////////////////////////
@ -139,7 +142,7 @@ main(int arg_count, char **args){
Arena test_arena = make_arena_malloc(); Arena test_arena = make_arena_malloc();
File_List list = system_get_file_list(&test_arena, File_List list = system_get_file_list(&test_arena,
string_u8_litexpr("/Users/yuvaldolev/Desktop/imgui")); string_u8_litexpr("/Users/yuvaldolev/Desktop"));
for (u32 index = 0; index < list.count; ++index) { for (u32 index = 0; index < list.count; ++index) {
File_Info* info = list.infos[index]; File_Info* info = list.infos[index];

View File

@ -200,13 +200,25 @@ system_quick_file_attributes_sig(){
return(result); return(result);
} }
function inline Plat_Handle
mac_to_plat_handle(i32 fd){
Plat_Handle result = *(Plat_Handle*)(&fd);
return result;
}
function inline i32
mac_to_fd(Plat_Handle handle){
i32 result = *(i32*)(&handle);
return result;
}
function function
system_load_handle_sig(){ system_load_handle_sig(){
b32 result = false; b32 result = false;
i32 fd = open(file_name, O_RDONLY); i32 fd = open(file_name, O_RDONLY);
if ((fd != -1) && (fd != 0)) { if ((fd != -1) && (fd != 0)) {
*(i32*)out = fd; *out = mac_to_plat_handle(fd);
result = true; result = true;
} }
@ -215,7 +227,7 @@ system_load_handle_sig(){
function function
system_load_attributes_sig(){ system_load_attributes_sig(){
i32 fd = *(i32*)(&handle); i32 fd = mac_to_fd(handle);
File_Attributes result = mac_file_attributes_from_fd(fd); File_Attributes result = mac_file_attributes_from_fd(fd);
return(result); return(result);
@ -223,7 +235,7 @@ system_load_attributes_sig(){
function function
system_load_file_sig(){ system_load_file_sig(){
i32 fd = *(i32*)(&handle); i32 fd = mac_to_fd(handle);
do{ do{
ssize_t bytes_read = read(fd, buffer, size); ssize_t bytes_read = read(fd, buffer, size);
@ -246,7 +258,7 @@ function
system_load_close_sig(){ system_load_close_sig(){
b32 result = true; b32 result = true;
i32 fd = *(i32*)(&handle); i32 fd = mac_to_fd(handle);
if (close(fd) == -1){ if (close(fd) == -1){
// NOTE(yuval): An error occured while close the file descriptor // NOTE(yuval): An error occured while close the file descriptor
result = false; result = false;
@ -289,29 +301,58 @@ system_save_file_sig(){
//////////////////////////////// ////////////////////////////////
function inline System_Library
mac_to_system_library(void* dl_handle){
System_Library result = *(System_Library*)(&dl_handle);
return result;
}
function inline void*
mac_to_dl_handle(System_Library system_lib){
void* result = *(void**)(&system_lib);
return result;
}
function function
system_load_library_sig(){ system_load_library_sig(){
b32 result = false; b32 result = false;
NotImplemented; void* lib = 0;
// NOTE(yuval): Open library handle
{
Temp_Memory temp = begin_temp(scratch);
char* c_file_name = push_array(scratch, char, file_name.size + 1);
block_copy(c_file_name, file_name.str, file_name.size);
c_file_name[file_name.size] = 0;
lib = dlopen(c_file_name, RTLD_LAZY | RTLD_GLOBAL);
end_temp(temp);
}
if (lib){
*out = mac_to_system_library(lib);
result = true;
}
return(result); return(result);
} }
function function
system_release_library_sig(){ system_release_library_sig(){
b32 result = false; void* lib = mac_to_dl_handle(handle);
i32 rc = dlclose(lib);
NotImplemented;
b32 result = (rc == 0);
return(result); return(result);
} }
function function
system_get_proc_sig(){ system_get_proc_sig(){
Void_Func* result = 0; void* lib = mac_to_dl_handle(handle);
Void_Func* result = (Void_Func*)dlsym(lib, proc_name);
NotImplemented;
return(result); return(result);
} }