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
|
|
|
|
system_load_library_direct(Library *library, char *name);
|
|
|
|
|
|
|
|
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
|
|
|
|
system_load_library(Library *library, char *name, Load_Library_Location location, char *full_file_out, u32 full_file_max){
|
|
|
|
char space[4096];
|
|
|
|
String extension = file_extension(make_string_slowly(name));
|
|
|
|
if (!match(extension, DLL)){
|
|
|
|
String full_name = make_fixed_width_string(space);
|
|
|
|
append(&full_name, name);
|
2017-10-31 07:14:24 +00:00
|
|
|
append(&full_name, "." DLL);
|
2017-07-19 16:33:12 +00:00
|
|
|
if (terminate_with_null(&full_name)){
|
|
|
|
name = space;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
name = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char path_space[4096];
|
|
|
|
String path = make_fixed_width_string(path_space);
|
|
|
|
switch (location){
|
|
|
|
case LoadLibrary_CurrentDirectory:
|
|
|
|
{
|
|
|
|
path.size = sysfunc.get_current_path(path.str, path.memory_size);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case LoadLibrary_BinaryDirectory:
|
|
|
|
{
|
|
|
|
path.size = sysfunc.get_4ed_path(path.str, path.memory_size);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
default: LOG("Invalid library location passed.\n"); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
b32 success = false;
|
|
|
|
if (path.size > 0){
|
2017-11-28 19:11:44 +00:00
|
|
|
if (path.str[path.size - 1] != SLASH){
|
|
|
|
append(&path, SLASH);
|
|
|
|
}
|
2017-07-19 16:33:12 +00:00
|
|
|
append(&path, name);
|
|
|
|
terminate_with_null(&path);
|
|
|
|
success = system_load_library_direct(library, path.str);
|
|
|
|
if (success && full_file_out != 0){
|
|
|
|
String out = make_string_cap(full_file_out, 0, full_file_max);
|
|
|
|
copy(&out, path);
|
|
|
|
terminate_with_null(&out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
system_load_library(Library *library, char *name, Load_Library_Location location){
|
2017-07-19 20:07:50 +00:00
|
|
|
b32 result = system_load_library(library, name, location, 0, 0);
|
|
|
|
return(result);
|
2017-07-19 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|