2017-07-19 16:33:12 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 19.07.2017
|
|
|
|
*
|
|
|
|
* Cross platform library constants
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FRED_SHARED_LIBRARY_CONSTANTS_H)
|
|
|
|
#define FRED_SHARED_LIBRARY_CONSTANTS_H
|
|
|
|
|
|
|
|
// Wrapper functions
|
|
|
|
union Library;
|
|
|
|
|
|
|
|
internal b32
|
2019-08-16 15:01:17 +00:00
|
|
|
system_load_library_direct(Arena *scratch, Library *library, char *name);
|
2017-07-19 16:33:12 +00:00
|
|
|
|
|
|
|
internal void*
|
|
|
|
system_get_proc(Library *library, char *name);
|
|
|
|
|
|
|
|
internal void
|
|
|
|
system_free_library(Library *library);
|
|
|
|
|
|
|
|
// Shared logic
|
|
|
|
#define LIBRARY_TYPE_SIZE 32
|
|
|
|
|
|
|
|
#define AssertLibrarySizes() Assert(sizeof(Library) == LIBRARY_TYPE_SIZE)
|
|
|
|
|
|
|
|
typedef u32 Load_Library_Location;
|
|
|
|
enum{
|
|
|
|
LoadLibrary_CurrentDirectory,
|
|
|
|
LoadLibrary_BinaryDirectory,
|
|
|
|
};
|
|
|
|
|
|
|
|
internal b32
|
2019-07-21 18:16:34 +00:00
|
|
|
system_load_library(Arena *scratch, Library *library, char *name_cstr, Load_Library_Location location, char *full_file_out, u32 full_file_max){
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
|
|
|
|
String_Const_char name = SCchar(name_cstr);
|
|
|
|
String_Const_char extension = string_file_extension(name);
|
|
|
|
if (!string_match(extension, string_litexpr( DLL ))){
|
|
|
|
String_Const_char full_name = push_stringf(scratch, "%.*s." DLL, string_expand(name));
|
|
|
|
name_cstr = full_name.str;
|
2017-07-19 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 07:41:40 +00:00
|
|
|
String_Const_u8 path = {};
|
2017-07-19 16:33:12 +00:00
|
|
|
switch (location){
|
|
|
|
case LoadLibrary_CurrentDirectory:
|
|
|
|
{
|
2019-07-24 07:41:40 +00:00
|
|
|
path = sysfunc.get_current_path(scratch);
|
2017-07-19 16:33:12 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case LoadLibrary_BinaryDirectory:
|
|
|
|
{
|
2019-07-24 07:41:40 +00:00
|
|
|
path = sysfunc.get_4ed_path(scratch);
|
2017-07-19 16:33:12 +00:00
|
|
|
}break;
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
//default: LOG("Invalid library location passed.\n"); break;
|
2017-07-19 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b32 success = false;
|
|
|
|
if (path.size > 0){
|
2017-11-28 19:11:44 +00:00
|
|
|
if (path.str[path.size - 1] != SLASH){
|
2019-07-24 07:41:40 +00:00
|
|
|
path = push_u8_stringf(scratch, "%.*s%c%.*s", string_expand(path), SLASH, string_expand(name));
|
2019-07-21 18:16:34 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-07-24 07:41:40 +00:00
|
|
|
path = push_u8_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name));
|
2017-11-28 19:11:44 +00:00
|
|
|
}
|
2019-08-16 15:01:17 +00:00
|
|
|
success = system_load_library_direct(scratch, library, (char*)path.str);
|
|
|
|
}
|
|
|
|
if (success && full_file_out != 0 && full_file_out > 0){
|
|
|
|
u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1));
|
|
|
|
block_copy(full_file_out, path.str, fill_size);
|
|
|
|
full_file_out[fill_size] = 0;
|
2017-07-19 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
end_temp(temp);
|
|
|
|
|
2017-07-19 16:33:12 +00:00
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
2019-07-21 18:16:34 +00:00
|
|
|
system_load_library(Arena *scratch, Library *library, char *name, Load_Library_Location location){
|
|
|
|
return(system_load_library(scratch, library, name, location, 0, 0));
|
2017-07-19 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|