blob: de7c83b7f4d5c4a365dce3c341dd0399bf3356cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <stdbool.h>
#include <stdlib.h>
#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
/* include winapi */
#else
#include <dlfcn.h>
#endif
#include <engine/logging.h>
#include <engine/dltools.h>
bool
dynamic_library_close(void* shared_library) {
#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
return true;
#else
return dlclose(shared_library) == 0;
#endif
}
void*
dynamic_library_open(const char *library_path) {
#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
return NULL;
#else
return dlopen(library_path, RTLD_NOW);
#endif
}
char* dynamic_library_get_error(void) {
#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
return "unsupported on windows";
#else
return dlerror();
#endif
}
void*
dynamic_library_reload(void* shared_library, const char *library_path) {
void* library_address = NULL;
if (!dynamic_library_close(shared_library)) {
ERROR("Failed to close shared library: %s", dynamic_library_get_error());
ERROR("Reloading dynamic library failed.");
return library_address;
}
if ((library_address = dynamic_library_open(library_path)) == NULL) {
ERROR("Failed to open shared library: %s", dynamic_library_get_error());
ERROR("Reloading dynamic library %s failed.", library_path);
}
return library_address;
}
void*
dynamic_library_get_symbol(void *restrict shared_library, const char *symbol) {
#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
return NULL;
#else
return dlsym(shared_library, symbol);
#endif
}
|