2007-06-06 18:12:30 +00:00
|
|
|
/* dynload.h - Wrapper functions for run-time dynamic loading
|
2010-02-26 18:44:36 +00:00
|
|
|
* Copyright (C) 2003, 2010 Free Software Foundation, Inc.
|
2007-06-06 18:12:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of JNLIB.
|
|
|
|
*
|
|
|
|
* JNLIB is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
2007-07-04 19:49:40 +00:00
|
|
|
* published by the Free Software Foundation; either version 3 of
|
2007-06-06 18:12:30 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* JNLIB 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2007-07-04 19:49:40 +00:00
|
|
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2007-06-06 18:12:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBJNLIB_DYNLOAD_H
|
|
|
|
#define LIBJNLIB_DYNLOAD_H
|
|
|
|
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#else
|
|
|
|
# include <windows.h>
|
2010-02-26 18:44:36 +00:00
|
|
|
# include "utf8conv.h"
|
|
|
|
# include "mischelp.h"
|
2007-06-06 18:12:30 +00:00
|
|
|
# define RTLD_LAZY 0
|
|
|
|
|
|
|
|
static inline void *
|
2010-02-26 18:44:36 +00:00
|
|
|
dlopen (const char *name, int flag)
|
2007-06-06 18:12:30 +00:00
|
|
|
{
|
2010-02-26 18:44:36 +00:00
|
|
|
void *hd;
|
|
|
|
#ifdef HAVE_W32CE_SYSTEM
|
|
|
|
wchar_t *wname = utf8_to_wchar (name);
|
|
|
|
hd = wname? LoadLibrary (wname) : NULL;
|
|
|
|
_jnlib_free (wname);
|
|
|
|
#else
|
|
|
|
hd = LoadLibrary (name);
|
|
|
|
#endif
|
2008-10-17 19:18:46 +00:00
|
|
|
(void)flag;
|
2007-06-06 18:12:30 +00:00
|
|
|
return hd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
dlsym (void *hd, const char *sym)
|
|
|
|
{
|
|
|
|
if (hd && sym)
|
|
|
|
{
|
2010-02-26 18:44:36 +00:00
|
|
|
#ifdef HAVE_W32CE_SYSTEM
|
|
|
|
wchar_t *wsym = utf8_to_wchar (sym);
|
|
|
|
void *fnc = wsym? GetProcAddress (hd, wsym) : NULL;
|
|
|
|
_jnlib_free (wsym);
|
|
|
|
#else
|
|
|
|
void *fnc = GetProcAddress (hd, sym);
|
|
|
|
#endif
|
2007-06-06 18:12:30 +00:00
|
|
|
if (!fnc)
|
|
|
|
return NULL;
|
|
|
|
return fnc;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
dlerror (void)
|
|
|
|
{
|
|
|
|
static char buf[32];
|
2010-02-26 18:44:36 +00:00
|
|
|
snprintf (buf, sizeof buf, "ec=%lu", GetLastError ());
|
2007-06-06 18:12:30 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
dlclose (void * hd)
|
|
|
|
{
|
|
|
|
if (hd)
|
|
|
|
{
|
|
|
|
CloseHandle (hd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
2011-02-04 12:57:53 +01:00
|
|
|
}
|
2007-06-06 18:12:30 +00:00
|
|
|
# endif /*__MINGW32__*/
|
|
|
|
#endif /*LIBJNLIB_DYNLOAD_H*/
|