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
|
local dat = {}
local ver, info
local datread = require("data/load_dat")
datread, ver = datread.open("sysinfo.dat", "# This file was generated on")
function dat.check(set, softlist)
if softlist or not datread then
return nil
end
local status
status, info = pcall(datread, "bio", "info", set)
if not status or not info then
return nil
end
return _("Sysinfo")
end
function dat.get()
return info
end
function dat.ver()
return ver
end
return dat
me.Function.Magic */
.highlight .vc { color: #369 } /* Name.Variable.Class */
.highlight .vg { color: #D70 } /* Name.Variable.Global */
.highlight .vi { color: #33B } /* Name.Variable.Instance */
.highlight .vm { color: #369 } /* Name.Variable.Magic */
.highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* dynlib.c
*
*/
#include "pdynlib.h"
#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 {
dynlib::dynlib(const pstring &libname)
: m_isLoaded(false), 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);
else
m_lib = GetModuleHandle(nullptr);
if (m_lib != nullptr)
m_isLoaded = 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 != "")
m_lib = dlopen(libname.c_str(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
if (m_lib != nullptr)
m_isLoaded = true;
//else
// printf("library <%s> not found: %s\n", libname.c_str(), dlerror());
#endif
}
dynlib::dynlib(const pstring &path, const pstring &libname)
: m_isLoaded(false), m_lib(nullptr)
{
// FIXME: implement path search
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);
else
m_lib = GetModuleHandle(nullptr);
if (m_lib != nullptr)
m_isLoaded = 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 != "")
m_lib = dlopen(libname.c_str(), RTLD_LAZY);
else
m_lib = dlopen(nullptr, RTLD_LAZY);
if (m_lib != nullptr)
m_isLoaded = true;
else
{
//printf("library <%s> not found!\n", libname.c_str());
}
#endif
}
dynlib::~dynlib()
{
if (m_lib != nullptr)
{
#ifdef _WIN32
#else
dlclose(m_lib);
//printf("Closed %s\n", dlerror());
#endif
}
}
bool dynlib::isLoaded() const
{
return m_isLoaded;
}
void *dynlib::getsym_p(const pstring &name)
{
#ifdef _WIN32
return (void *) GetProcAddress((HMODULE) m_lib, name.c_str());
#else
return dlsym(m_lib, name.c_str());
#endif
}
} // namespace plib
|