/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 :
 * =====================================================================
 *  sc_dl.c
 *  Copyright (c)  2003 - 2011  sys0tem
 *  LICENSE :
 *	LGPL (GNU Lesser General Public License - Version 3,29 June 2007)
 *	http://www.gnu.org/copyleft/lesser.html
 *	or
 *	EPL (Eclipse Public License - v1.0)
 *	http://www.eclipse.org/legal/epl-v10.html
 * =====================================================================
 */
#include <sc_dl.h>

/* =====================================================================
 *  プロトタイプ宣言
 * =====================================================================
 */

dl_handle_t SC_DL_open(const char* fileName)
{
	dl_handle_t handle;
#if (SC_isWindows)
	handle = LoadLibrary(fileName);
#else
	handle = dlopen(fileName, RTLD_NOW);
#endif
	return handle;
}

void* SC_DL_sym(dl_handle_t handle, const char* symbol)
{
	void* func;
#if (SC_isWindows)
	func = (void*) GetProcAddress(handle, symbol);
#else
	func = dlsym(handle, symbol);
#endif
	return func;
}

bool SC_DL_close(dl_handle_t handle)
{
#if (SC_isWindows)
	BOOL ret = FreeLibrary(handle);
	return (bool) ret;
#else
	int ret = dlclose(handle);
	return (ret == 0);
#endif
}

