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
29 /* This whole file is conditional upon HAVE_SHLIB */
32 /* Thankfully, most systems follow the ELFish dlopen() method.
34 #if defined(HAVE_DLOPEN)
39 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
42 # define RTLD_GLOBAL 0
50 dll_init (const char *arg)
56 dll_open (const char *fname)
58 return (dll_handle) dlopen (fname, RTLD_NOW | RTLD_GLOBAL);
62 dll_close (dll_handle h)
64 return dlclose ((void *) h);
68 dll_function (dll_handle h, const char *n)
70 #ifdef DLSYM_NEEDS_UNDERSCORE
71 char *buf = alloca_array (char, strlen (n) + 2);
76 return (dll_func) dlsym ((void *) h, n);
80 dll_variable (dll_handle h, const char *n)
82 #ifdef DLSYM_NEEDS_UNDERSCORE
83 char *buf = alloca_array (char, strlen (n) + 2);
88 return (dll_var)dlsym ((void *)h, n);
92 dll_error (dll_handle h)
94 #if defined(HAVE_DLERROR) || defined(dlerror)
95 return (const char *) dlerror ();
96 #elif defined(HAVE__DLERROR)
97 return (const char *) _dlerror();
99 return "Shared library error";
103 #elif defined(HAVE_SHL_LOAD)
104 /* This is the HP/UX version */
107 dll_init (const char *arg)
113 dll_open (const char *fname)
115 /* shl_load will hang hard if passed a NULL fname. */
116 if (fname == NULL) return NULL;
118 return (dll_handle) shl_load (fname, BIND_DEFERRED,0L);
122 dll_close (dll_handle h)
124 return shl_unload ((shl_t) h);
128 dll_function (dll_handle h, const char *n)
132 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
135 return (dll_func) handle;
139 dll_variable (dll_handle h, const char *n)
143 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
146 return (dll_var) handle;
150 dll_error (dll_handle h)
152 /* #### WTF?! Shouldn't this at least attempt to get strerror or
153 something? --hniksic */
154 return "Generic shared library error";
157 #elif defined(HAVE_INIT_DLD)
160 dll_init (const char *arg)
162 char *real_exe = dld_find_executable (arg);
165 rc = dld_init (real_exe);
175 dll_open (const char *fname)
177 rc = dld_link (fname);
181 return (dll_handle) 1;
185 dll_close (dll_handle h)
187 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
188 ** later on to free the file - you have to remember the filename and
189 ** use that as the unlinker. We should eventually keep a linked list
190 ** of loaded modules and then use the node pointer as the unique id
191 ** for the shared library. Wheeee. But not now.
197 dll_function (dll_handle h, const char *n)
199 return dld_get_func (n);
203 dll_variable (dll_handle h, const char *n)
205 return dld_get_symbol (n);
207 #elif defined (WIN32_NATIVE)
209 #define WIN32_LEAN_AND_MEAN
211 #undef WIN32_LEAN_AND_MEAN
214 dll_init (const char *arg)
220 dll_open (const char *fname)
222 return (dll_handle) LoadLibrary (fname);
226 dll_close (dll_handle h)
228 return FreeLibrary (h);
232 dll_function (dll_handle h, const char *n)
234 return (dll_func) GetProcAddress (h, n);
238 dll_variable (dll_handle h, const char *n)
240 return (dll_func) GetProcAddress (h, n);
244 dll_error (dll_handle h)
246 return "Windows DLL Error";
249 /* Catchall if we don't know about this systems method of dynamic loading */
251 dll_init (const char *arg)
257 dll_open (const char *fname)
263 dll_close (dll_handle h)
269 dll_function (dll_handle h, const char *n)
275 dll_variable (dll_handle h, const char *n)
281 dll_error (dll_handle h)
283 return "Shared libraries not implemented on this system";
285 #endif /* System conditionals */
287 #endif /* HAVE_SHLIB */