1 /* sysdll.c --- system dependent support for dynamic linked libraries
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Author: William Perry <wmperry@aventail.com>
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to the Free
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 /* This whole file is conditional upon HAVE_SHLIB */
33 /* Thankfully, most systems follow the ELFish dlopen() method.
35 #if defined(HAVE_DLOPEN)
40 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
47 dll_init (const char *arg)
53 dll_open (const char *fname)
55 return (dll_handle) dlopen (fname, RTLD_NOW);
59 dll_close (dll_handle h)
61 return dlclose ((void *) h);
65 dll_function (dll_handle h, const char *n)
67 #ifdef DLSYM_NEEDS_UNDERSCORE
68 char *buf = alloca_array (char, strlen (n) + 2);
73 return (dll_func) dlsym ((void *) h, n);
77 dll_variable (dll_handle h, const char *n)
79 #ifdef DLSYM_NEEDS_UNDERSCORE
80 char *buf = alloca_array (char, strlen (n) + 2);
85 return (dll_var)dlsym ((void *)h, n);
89 dll_error (dll_handle h)
91 #if defined(HAVE_DLERROR) || defined(dlerror)
92 return (const char *) dlerror ();
93 #elif defined(HAVE__DLERROR)
94 return (const char *) _dlerror();
96 return "Shared library error";
100 #elif defined(HAVE_SHL_LOAD)
101 /* This is the HP/UX version */
104 dll_init (const char *arg)
110 dll_open (const char *fname)
112 /* shl_load will hang hard if passed a NULL fname. */
113 if (fname == NULL) return NULL;
115 return (dll_handle) shl_load (fname, BIND_DEFERRED,0L);
119 dll_close (dll_handle h)
121 return shl_unload ((shl_t) h);
125 dll_function (dll_handle h, const char *n)
129 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
132 return (dll_func) handle;
136 dll_variable (dll_handle h, const char *n)
140 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
143 return (dll_var) handle;
147 dll_error (dll_handle h)
149 /* #### WTF?! Shouldn't this at least attempt to get strerror or
150 something? --hniksic */
151 return "Generic shared library error";
154 #elif defined(HAVE_INIT_DLD)
157 dll_init (const char *arg)
159 char *real_exe = dld_find_executable (arg);
162 rc = dld_init (real_exe);
172 dll_open (const char *fname)
174 rc = dld_link (fname);
178 return (dll_handle) 1;
182 dll_close (dll_handle h)
184 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
185 ** later on to free the file - you have to remember the filename and
186 ** use that as the unlinker. We should eventually keep a linked list
187 ** of loaded modules and then use the node pointer as the unique id
188 ** for the shared library. Wheeee. But not now.
194 dll_function (dll_handle h, const char *n)
196 return dld_get_func (n);
200 dll_variable (dll_handle h, const char *n)
202 return dld_get_symbol (n);
204 #elif defined (WIN32_NATIVE)
206 #define WIN32_LEAN_AND_MEAN
208 #undef WIN32_LEAN_AND_MEAN
211 dll_init (const char *arg)
217 dll_open (const char *fname)
219 return (dll_handle) LoadLibrary (fname);
223 dll_close (dll_handle h)
225 return FreeLibrary (h);
229 dll_function (dll_handle h, const char *n)
231 return (dll_func) GetProcAddress (h, n);
235 dll_variable (dll_handle h, const char *n)
237 return (dll_func) GetProcAddress (h, n);
241 dll_error (dll_handle h)
243 return "Windows DLL Error";
246 /* Catchall if we don't know about this systems method of dynamic loading */
248 dll_init (const char *arg)
254 dll_open (const char *fname)
260 dll_close (dll_handle h)
266 dll_function (dll_handle h, const char *n)
272 dll_variable (dll_handle h, const char *n)
278 dll_error (dll_handle h)
280 return "Shared libraries not implemented on this system";
282 #endif /* System conditionals */
284 #endif /* HAVE_SHLIB */