summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pdynlib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pdynlib.cpp')
-rw-r--r--src/lib/netlist/plib/pdynlib.cpp82
1 files changed, 15 insertions, 67 deletions
diff --git a/src/lib/netlist/plib/pdynlib.cpp b/src/lib/netlist/plib/pdynlib.cpp
index 3fb5c70a171..6268ad450de 100644
--- a/src/lib/netlist/plib/pdynlib.cpp
+++ b/src/lib/netlist/plib/pdynlib.cpp
@@ -5,83 +5,39 @@
#ifdef _WIN32
#include "windows.h"
-#include "palloc.h"
-
-namespace plib {
-CHAR *astring_from_utf8(const char *utf8string)
-{
- WCHAR *wstring;
- int char_count;
- CHAR *result;
-
- // convert MAME string (UTF-8) to UTF-16
- char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0);
- wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
- MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
-
- // convert UTF-16 to "ANSI code page" string
- char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, nullptr, 0, nullptr, nullptr);
- result = new CHAR[char_count];
- if (result != nullptr)
- WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, nullptr, nullptr);
-
- return result;
-}
-
-WCHAR *wstring_from_utf8(const char *utf8string)
-{
- int char_count;
- WCHAR *result;
-
- // convert MAME string (UTF-8) to UTF-16
- char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0);
- result = new WCHAR[char_count];
- if (result != nullptr)
- MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
-
- return result;
-}
-}
-
-#ifdef UNICODE
-#define tstring_from_utf8 plib::wstring_from_utf8
-#else // !UNICODE
-#define tstring_from_utf8 plib::astring_from_utf8
-#endif // UNICODE
-
#else
#include <dlfcn.h>
#endif
-namespace plib {
+#include <type_traits>
+
+namespace plib
+{
+ using winapi_string = std::conditional<compile_info::unicode::value,
+ pwstring, pu8string>::type;
+
dynlib::dynlib(const pstring &libname)
: m_lib(nullptr)
{
#ifdef _WIN32
//fprintf(stderr, "win: loading <%s>\n", libname.c_str());
- TCHAR *buffer = tstring_from_utf8(libname.c_str());
- if (libname != "")
- m_lib = LoadLibrary(buffer);
+ if (!libname.empty())
+ m_lib = LoadLibrary(winapi_string(libname).c_str());
else
m_lib = GetModuleHandle(nullptr);
- if (m_lib != nullptr)
- set_loaded(true);
- //else
- // fprintf(stderr, "win: library <%s> not found!\n", libname.c_str());
- delete [] buffer;
#elif defined(__EMSCRIPTEN__)
//no-op
#else
//printf("loading <%s>\n", libname.c_str());
- if (libname != "")
+ if (!libname.empty())
m_lib = dlopen(libname.c_str(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
+#endif
if (m_lib != nullptr)
set_loaded(true);
//else
// printf("library <%s> not found: %s\n", libname.c_str(), dlerror());
-#endif
}
dynlib::dynlib(const pstring &path, const pstring &libname)
@@ -91,33 +47,25 @@ dynlib::dynlib(const pstring &path, const pstring &libname)
plib::unused_var(path);
// printf("win: loading <%s>\n", libname.c_str());
#ifdef _WIN32
- TCHAR *buffer = tstring_from_utf8(libname.c_str());
- if (libname != "")
- m_lib = LoadLibrary(buffer);
+ if (!libname.empty())
+ m_lib = LoadLibrary(winapi_string(libname).c_str());
else
m_lib = GetModuleHandle(nullptr);
- if (m_lib != nullptr)
- set_loaded(true);
- else
- {
- //printf("win: library <%s> not found!\n", libname.c_str());
- }
- delete [] buffer;
#elif defined(__EMSCRIPTEN__)
//no-op
#else
//printf("loading <%s>\n", libname.c_str());
- if (libname != "")
+ if (!libname.empty())
m_lib = dlopen(libname.c_str(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
+#endif
if (m_lib != nullptr)
set_loaded(true);
else
{
//printf("library <%s> not found!\n", libname.c_str());
}
-#endif
}
dynlib::~dynlib()