-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from larsewi/strndup
Fixed issue with strndup on Windows
- Loading branch information
Showing
8 changed files
with
153 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "module.h" | ||
|
||
#include <stdlib.h> | ||
|
||
#if HAVE_DLFCN_H | ||
#include <dlfcn.h> | ||
#endif // HAVE_DLFCN_H | ||
|
||
#if _WIN32 | ||
#include <libloaderapi.h> | ||
#endif // _WIN32 | ||
|
||
#include "logger.h" | ||
|
||
void *LCH_ModuleLoad(const char *const path) { | ||
LCH_LOG_DEBUG("Loading dynamic shared library '%s'", path); | ||
#if HAVE_DLFCN_H | ||
void *handle = dlopen(path, RTLD_NOW); | ||
if (handle == NULL) { | ||
LCH_LOG_ERROR("Failed to load dynamic shared library '%s': %s", path, | ||
dlerror()); | ||
return NULL; | ||
} | ||
return handle; | ||
#elif defined(_WIN32) | ||
void *handle = LoadLibraryA(path); | ||
if (handle == NULL) { | ||
LCH_LOG_ERROR("Failed to load dynamic shared library '%s': Error code %lu", | ||
path, GetLastError()); | ||
} | ||
return handle; | ||
#else | ||
LCH_LOG_ERROR("Failed to load dynamic shared library '%s'", path); | ||
return NULL; | ||
#endif | ||
} | ||
|
||
void *LCH_ModuleGetSymbol(void *const handle, const char *const symbol) { | ||
LCH_LOG_DEBUG("Obtaining address of symbol '%s'", symbol); | ||
#if HAVE_DLFCN_H | ||
void *address = dlsym(handle, symbol); | ||
if (address == NULL) { | ||
LCH_LOG_ERROR("Failed to obtain address of symbol '%s': %s", symbol, | ||
dlerror()); | ||
return NULL; | ||
} | ||
return address; | ||
#elif defined(_WIN32) | ||
void *address = GetProcAddress(handle, symbol); | ||
if (address == NULL) { | ||
LCH_LOG_ERROR("Failed to obtain address of symbol '%s': Error code %lu", | ||
symbol, GetLastError()); | ||
} | ||
return address; | ||
#else | ||
LCH_LOG_ERROR("Failed to obtain address of symbol '%s'", symbol); | ||
return NULL; | ||
#endif | ||
} | ||
|
||
void LCH_ModuleDestroy(void *const handle) { | ||
if (handle == NULL) { | ||
return; | ||
} | ||
#if HAVE_DLFCN_H | ||
if (dlclose(handle) != 0) { | ||
LCH_LOG_WARNING("Failed to release handle to dynamic shared library: %s", | ||
dlerror()); | ||
} | ||
#elif defined(_WIN32) | ||
if (FreeLibrary(handle) == 0) { | ||
LCH_LOG_WARNING( | ||
"Failed to release handle to dynamic shared library: Error code %lu", | ||
GetLastError()); | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _LEECH_MODULE_H | ||
#define _LEECH_MODULE_H | ||
|
||
#include <stdbool.h> | ||
|
||
void *LCH_ModuleLoad(const char *path); | ||
|
||
void *LCH_ModuleGetSymbol(void *handle, const char *const symbol); | ||
|
||
void LCH_ModuleDestroy(void *handle); | ||
|
||
#endif // _LEECH_MODULE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.