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
|
|
|
*
|
2015-04-24 16:42:28 +02:00
|
|
|
* This file is part of GnuPG.
|
2007-06-06 18:12:30 +00:00
|
|
|
*
|
2017-02-24 13:48:28 +01:00
|
|
|
* GnuPG is free software; you can redistribute and/or modify this
|
|
|
|
* part of GnuPG under the terms of either
|
2011-09-30 12:52:11 +02:00
|
|
|
*
|
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
2007-06-06 18:12:30 +00:00
|
|
|
*
|
2015-04-24 16:42:28 +02:00
|
|
|
* GnuPG is distributed in the hope that it will be useful, but
|
2007-06-06 18:12:30 +00:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2011-09-30 12:52:11 +02:00
|
|
|
* General Public License for more details.
|
2007-06-06 18:12:30 +00:00
|
|
|
*
|
2011-09-30 12:52:11 +02:00
|
|
|
* You should have received a copies of the GNU General Public License
|
|
|
|
* and the GNU Lesser General Public License along with this program;
|
2016-11-05 12:02:19 +01:00
|
|
|
* if not, see <https://www.gnu.org/licenses/>.
|
2007-06-06 18:12:30 +00:00
|
|
|
*/
|
|
|
|
|
2015-04-24 16:42:28 +02:00
|
|
|
#ifndef GNUPG_COMMON_DYNLOAD_H
|
|
|
|
#define GNUPG_COMMON_DYNLOAD_H
|
2007-06-06 18:12:30 +00:00
|
|
|
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#else
|
2024-02-15 14:40:33 +09:00
|
|
|
# ifdef HAVE_WINSOCK2_H
|
|
|
|
# include <winsock2.h>
|
|
|
|
# endif
|
|
|
|
# include <windows.h>
|
2010-02-26 18:44:36 +00:00
|
|
|
# include "utf8conv.h"
|
|
|
|
# include "mischelp.h"
|
2024-02-15 14:40:33 +09:00
|
|
|
# ifndef RTLD_LAZY
|
|
|
|
# define RTLD_LAZY 0
|
|
|
|
# endif
|
2007-06-06 18:12:30 +00:00
|
|
|
|
|
|
|
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;
|
2008-10-17 19:18:46 +00:00
|
|
|
(void)flag;
|
2022-06-03 11:11:28 +02:00
|
|
|
|
|
|
|
hd = LoadLibraryEx (name, NULL, 0);
|
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
|
|
|
void *fnc = GetProcAddress (hd, sym);
|
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__*/
|
2015-04-24 16:42:28 +02:00
|
|
|
#endif /*GNUPG_COMMON_DYNLOAD_H*/
|