/**
* @file kc_dl.c
* @brief 動的ライブラリモジュール
* @copyright 2003 - 2023 Nomura Kei
*/
#include <kc_dl.h>
/**
* 指定された動的ライブラリをオープンします。
*
* @param filename 動的ライブラリのファイル名
*/
dl_handle_t KcDl_open(const char *filename)
{
dl_handle_t handle;
#if (KC_IS_WINDOWS)
handle = LoadLibrary(filename);
#else
handle = dlopen(filename, RTLD_NOW);
#endif
return handle;
}
/**
* 動的ライブラリの関数を取得します。
*
* @param handle ハンドル
* @param symbol 関数のシンボル名
* @return 関数
*/
void *KcDl_sym(dl_handle_t handle, const char *symbol)
{
void *func;
#if (KC_IS_WINDOWS)
func = (void *)GetProcAddress(handle, symbol);
#else
func = dlsym(handle, symbol);
#endif
return func;
}
/**
* 動的ライブラリをクローズします。
*
* @param handle クローズするハンドル
*/
bool KcDl_close(dl_handle_t handle)
{
#if (KC_IS_WINDOWS)
BOOL ret = FreeLibrary(handle);
return (bool)ret;
#else
int ret = dlclose(handle);
return (ret == 0);
#endif
}