4 * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 #ident "$Id: ivl_dlfcn.h,v 1.3 2004/10/04 01:10:56 steve Exp $"
25 #if defined(__MINGW32__)
28 typedef void * ivl_dll_t
;
29 #elif defined(HAVE_DLFCN_H)
31 typedef void* ivl_dll_t
;
32 #elif defined(HAVE_DL_H)
34 typedef shl_t ivl_dll_t
;
37 #if defined(__MINGW32__)
38 static inline ivl_dll_t
ivl_dlopen(const char *name
)
39 { return (void *)LoadLibrary(name
); }
41 static inline void *ivl_dlsym(ivl_dll_t dll
, const char *nm
)
42 { return (void *)GetProcAddress((HINSTANCE
)dll
,nm
);}
44 static inline void ivl_dlclose(ivl_dll_t dll
)
45 { (void)FreeLibrary((HINSTANCE
)dll
);}
47 static inline const char *dlerror(void)
50 unsigned long err
= GetLastError();
52 FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
55 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
63 #elif defined(HAVE_DLFCN_H)
64 static inline ivl_dll_t
ivl_dlopen(const char*name
)
65 { return dlopen(name
,RTLD_LAZY
); }
67 static inline void* ivl_dlsym(ivl_dll_t dll
, const char*nm
)
69 void*sym
= dlsym(dll
, nm
);
70 /* Not found? try without the leading _ */
71 if (sym
== 0 && nm
[0] == '_')
72 sym
= dlsym(dll
, nm
+1);
76 static inline void ivl_dlclose(ivl_dll_t dll
)
79 #elif defined(HAVE_DL_H)
80 static inline ivl_dll_t
ivl_dlopen(const char*name
)
81 { return shl_load(name
, BIND_IMMEDIATE
, 0); }
83 static inline void* ivl_dlsym(ivl_dll_t dll
, const char*nm
)
86 int rc
= shl_findsym(&dll
, nm
, TYPE_PROCEDURE
, &sym
);
87 return (rc
== 0) ? sym
: 0;
90 static inline void ivl_dlclose(ivl_dll_t dll
)
93 static inline const char*dlerror(void)
94 { return strerror( errno
); }
98 * $Log: ivl_dlfcn.h,v $
99 * Revision 1.3 2004/10/04 01:10:56 steve
100 * Clean up spurious trailing white space.
102 * Revision 1.2 2003/12/12 05:43:08 steve
103 * Some systems dlsym requires leading _ or not on whim.
105 * Revision 1.1 2003/02/17 00:01:25 steve
106 * Use a variant of ivl_dlfcn to do dynamic loading
107 * from within the cadpli module.
109 * Change the +cadpli flag to -cadpli, to keep the
110 * plusargs namespace clear.