53 DWORD code = GetLastError();
54 DWORD n = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, 0, sys, (DWORD)
sizeof(sys), NULL);
57 while (n > 0 && (sys[n - 1] ==
'\r' || sys[n - 1] ==
'\n' || sys[n - 1] ==
' ')) sys[--n] =
'\0';
61 const char* sys = dlerror();
79 wchar_t wpath[MAX_PATH * 4];
80 int wlen = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, wpath, (
int)(
sizeof(wpath) /
sizeof(wpath[0])));
83 handle = (
void*)LoadLibraryW(wpath);
85 handle = (
void*)LoadLibraryA(path);
90 handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
99 FreeLibrary((HMODULE)handle);
106 module->handle = handle;
122 FARPROC proc = GetProcAddress((HMODULE)module->
handle, name);
124 if (proc) memcpy(&symbol, &proc,
sizeof(symbol));
130 symbol = dlsym(module->
handle, name);
139 if (!module || !*module)
return TRUE;
140 if ((*module)->handle) {
142 if (!FreeLibrary((HMODULE)(*module)->handle)) {
147 if (dlclose((*module)->handle) != 0) {
162#if defined(__windows__)
164#elif defined(__APPLE__)
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
const char * n_module_extension(void)
The file extension shared libraries have on this platform.
#define N_MODULE_ERROR_MAX
longest error text kept by n_module_error(), terminator included
N_MODULE * n_module_open(const char *path)
Open a shared library.
int n_module_close(N_MODULE **module)
Close a library and free its handle.
void * n_module_symbol(N_MODULE *module, const char *name)
Find a symbol in an opened library.
const char * n_module_error(void)
What the system said about this thread's last failed call.
static __thread char _n_module_last_error[512]
the last failure on this thread, as the system worded it
void * handle
dlopen handle, or HMODULE
static void _n_module_set_error(const char *what, const char *subject)
helper: record why what failed on subject, in the system's words
Load a shared library at runtime and find its symbols.