2006-09-06 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / common / dynload.h
blob9b67fa9edf829105ad581a224712e4d08c696cf3
1 /* dlfcn.h - W32 functions for run-time dynamic loading
2 * Copyright (C) 2003 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 #ifndef GNUPG_DYNLOAD_H
23 #define GNUPG_DYNLOAD_H
24 #ifndef __MINGW32__
25 #include <dlfcn.h>
26 #else
27 #include <windows.h>
29 #define RTLD_LAZY 0
31 static inline void *
32 dlopen (const char * name, int flag)
34 void * hd = LoadLibrary (name);
35 return hd;
38 static inline void *
39 dlsym (void *hd, const char *sym)
41 if (hd && sym)
43 void * fnc = GetProcAddress (hd, sym);
44 if (!fnc)
45 return NULL;
46 return fnc;
48 return NULL;
52 static inline const char *
53 dlerror (void)
55 static char buf[32];
56 sprintf (buf, "ec=%lu", GetLastError ());
57 return buf;
61 static inline int
62 dlclose (void * hd)
64 if (hd)
66 CloseHandle (hd);
67 return 0;
69 return -1;
71 #endif /*__MINGW32__*/
72 #endif /*GNUPG_DYNLOAD_H*/