Format dlopen.c
This commit is contained in:
parent
9181d91988
commit
4ec4a0ecf5
26
src/dlopen.c
26
src/dlopen.c
|
@ -1,7 +1,8 @@
|
||||||
#include "dlopen.h"
|
#include "dlopen.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct hotwire_dll_t hw_dlopen(const char *file, int flags) {
|
struct hotwire_dll_t hw_dlopen(const char* file, int flags)
|
||||||
|
{
|
||||||
|
|
||||||
struct hotwire_dll_t dll;
|
struct hotwire_dll_t dll;
|
||||||
|
|
||||||
|
@ -31,7 +32,8 @@ struct hotwire_dll_t hw_dlopen(const char *file, int flags) {
|
||||||
return dll;
|
return dll;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *hw_dlsym(struct hotwire_dll_t dll, const char *symbol) {
|
void* hw_dlsym(struct hotwire_dll_t dll, const char* symbol)
|
||||||
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return GetProcAddress(dll.dll_handle, symbol);
|
return GetProcAddress(dll.dll_handle, symbol);
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,11 +43,13 @@ void *hw_dlsym(struct hotwire_dll_t dll, const char *symbol) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
enum hotwire_status_code hw_dlclose(struct hotwire_dll_t handle) {
|
enum hotwire_status_code hw_dlclose(struct hotwire_dll_t handle)
|
||||||
|
{
|
||||||
#if defined(__linux) || defined(__APPLE__)
|
#if defined(__linux) || defined(__APPLE__)
|
||||||
if (dlclose(handle.dll_handle) != 0) {
|
if (dlclose(handle.dll_handle) != 0) {
|
||||||
return Failed;
|
return Failed;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,7 +57,8 @@ enum hotwire_status_code hw_dlclose(struct hotwire_dll_t handle) {
|
||||||
#if defined(__WIN32)
|
#if defined(__WIN32)
|
||||||
if (FreeLibrary(handle.dll_handle)) {
|
if (FreeLibrary(handle.dll_handle)) {
|
||||||
return Success;
|
return Success;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,22 +67,19 @@ enum hotwire_status_code hw_dlclose(struct hotwire_dll_t handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void hw_platform_win32_get_last_error(LPTSTR lpszFunction) {
|
void hw_platform_win32_get_last_error(LPTSTR lpszFunction)
|
||||||
|
{
|
||||||
LPVOID lpMsgBuf;
|
LPVOID lpMsgBuf;
|
||||||
LPVOID lpDisplayBuf;
|
LPVOID lpDisplayBuf;
|
||||||
DWORD dw = GetLastError();
|
DWORD dw = GetLastError();
|
||||||
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPTSTR)&lpMsgBuf, 0, NULL);
|
(LPTSTR)&lpMsgBuf, 0, NULL);
|
||||||
|
|
||||||
// Display the error message and exit the process
|
// Display the error message and exit the process
|
||||||
|
|
||||||
lpDisplayBuf =
|
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
|
||||||
(LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) +
|
|
||||||
lstrlen((LPCTSTR)lpszFunction) + 40) *
|
|
||||||
sizeof(TCHAR));
|
|
||||||
StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR),
|
StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR),
|
||||||
TEXT("%s failed with error %d: %s"), lpszFunction, dw,
|
TEXT("%s failed with error %d: %s"), lpszFunction, dw,
|
||||||
lpMsgBuf);
|
lpMsgBuf);
|
||||||
|
|
Loading…
Reference in a new issue