mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-22 02:30:56 +00:00
Create dylib.c - split up dylib functions
This commit is contained in:
parent
8290e89650
commit
812a873f0c
@ -122,6 +122,7 @@ OBJ += frontend/frontend.o \
|
||||
configuration.o \
|
||||
settings_list.o \
|
||||
settings.o \
|
||||
dylib.o \
|
||||
dynamic.o \
|
||||
dynamic_dummy.o \
|
||||
libretro-common/queues/message_queue.o \
|
||||
@ -729,5 +730,5 @@ endif
|
||||
|
||||
|
||||
# Joyconfig binary
|
||||
|
||||
JOYCONFIG_OBJ += tools/retroarch-joyconfig-griffin.o
|
||||
JOYCONFIG_LIBS += -ldl
|
||||
JOYCONFIG_OBJ += tools/retroarch-joyconfig-griffin.o
|
||||
|
100
dylib.c
Normal file
100
dylib.c
Normal file
@ -0,0 +1,100 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dynamic.h"
|
||||
#include "general.h"
|
||||
|
||||
#ifdef NEED_DYNAMIC
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* dylib_load:
|
||||
* @path : Path to libretro core library.
|
||||
*
|
||||
* Platform independent dylib loading.
|
||||
*
|
||||
* Returns: library handle on success, otherwise NULL.
|
||||
**/
|
||||
dylib_t dylib_load(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
dylib_t lib = LoadLibrary(path);
|
||||
if (!lib)
|
||||
RARCH_ERR("Failed to load library, error code: 0x%x\n",
|
||||
(unsigned)GetLastError());
|
||||
return lib;
|
||||
#else
|
||||
dylib_t lib = dlopen(path, RTLD_LAZY);
|
||||
if (!lib)
|
||||
RARCH_ERR("dylib_load() failed: \"%s\".\n", dlerror());
|
||||
return lib;
|
||||
#endif
|
||||
}
|
||||
|
||||
function_t dylib_proc(dylib_t lib, const char *proc)
|
||||
{
|
||||
function_t sym;
|
||||
void *ptr_sym = NULL;
|
||||
|
||||
(void)ptr_sym;
|
||||
|
||||
#ifdef _WIN32
|
||||
sym = (function_t)GetProcAddress(lib ?
|
||||
(HMODULE)lib : GetModuleHandle(NULL), proc);
|
||||
#else
|
||||
if (lib)
|
||||
ptr_sym = dlsym(lib, proc);
|
||||
else
|
||||
{
|
||||
void *handle = dlopen(NULL, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
ptr_sym = dlsym(handle, proc);
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dirty hack to workaround the non-legality of
|
||||
* (void*) -> fn-pointer casts. */
|
||||
memcpy(&sym, &ptr_sym, sizeof(void*));
|
||||
#endif
|
||||
|
||||
return sym;
|
||||
}
|
||||
|
||||
/**
|
||||
* dylib_close:
|
||||
* @lib : Library handle.
|
||||
*
|
||||
* Frees library handle.
|
||||
**/
|
||||
void dylib_close(dylib_t lib)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FreeLibrary((HMODULE)lib);
|
||||
#else
|
||||
#ifndef NO_DLCLOSE
|
||||
dlclose(lib);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
74
dynamic.c
74
dynamic.c
@ -496,80 +496,6 @@ void uninit_libretro_sym(void)
|
||||
retro_perf_clear();
|
||||
}
|
||||
|
||||
#ifdef NEED_DYNAMIC
|
||||
/**
|
||||
* dylib_load:
|
||||
* @path : Path to libretro core library.
|
||||
*
|
||||
* Platform independent dylib loading.
|
||||
*
|
||||
* Returns: library handle on success, otherwise NULL.
|
||||
**/
|
||||
dylib_t dylib_load(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
dylib_t lib = LoadLibrary(path);
|
||||
if (!lib)
|
||||
RARCH_ERR("Failed to load library, error code: 0x%x\n",
|
||||
(unsigned)GetLastError());
|
||||
return lib;
|
||||
#else
|
||||
dylib_t lib = dlopen(path, RTLD_LAZY);
|
||||
if (!lib)
|
||||
RARCH_ERR("dylib_load() failed: \"%s\".\n", dlerror());
|
||||
return lib;
|
||||
#endif
|
||||
}
|
||||
|
||||
function_t dylib_proc(dylib_t lib, const char *proc)
|
||||
{
|
||||
function_t sym;
|
||||
void *ptr_sym = NULL;
|
||||
|
||||
(void)ptr_sym;
|
||||
|
||||
#ifdef _WIN32
|
||||
sym = (function_t)GetProcAddress(lib ?
|
||||
(HMODULE)lib : GetModuleHandle(NULL), proc);
|
||||
#else
|
||||
if (lib)
|
||||
ptr_sym = dlsym(lib, proc);
|
||||
else
|
||||
{
|
||||
void *handle = dlopen(NULL, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
ptr_sym = dlsym(handle, proc);
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dirty hack to workaround the non-legality of
|
||||
* (void*) -> fn-pointer casts. */
|
||||
memcpy(&sym, &ptr_sym, sizeof(void*));
|
||||
#endif
|
||||
|
||||
return sym;
|
||||
}
|
||||
|
||||
/**
|
||||
* dylib_close:
|
||||
* @lib : Library handle.
|
||||
*
|
||||
* Frees library handle.
|
||||
**/
|
||||
void dylib_close(dylib_t lib)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FreeLibrary((HMODULE)lib);
|
||||
#else
|
||||
#ifndef NO_DLCLOSE
|
||||
dlclose(lib);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void rarch_log_libretro(enum retro_log_level level,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
|
@ -562,6 +562,7 @@ FILTERS
|
||||
/*============================================================
|
||||
DYNAMIC
|
||||
============================================================ */
|
||||
#include "../dylib.c"
|
||||
#include "../dynamic.c"
|
||||
#include "../dynamic_dummy.c"
|
||||
#include "../gfx/video_filter.c"
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include "retroarch-joyconfig.c"
|
||||
|
||||
#include "../dylib.c"
|
||||
|
||||
#if defined(__linux) && !defined(ANDROID)
|
||||
#include "../input/drivers/linuxraw_input.c"
|
||||
#include "../input/drivers_joypad/linuxraw_joypad.c"
|
||||
|
Loading…
x
Reference in New Issue
Block a user