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
28 /* This whole file is conditional upon HAVE_DLL */
31 /* Thankfully, most systems follow the ELFish dlopen() method.
32 ** HAVE__DLOPEN is lame, but SCO has their dl* functions as _dl*, and
33 ** unless you include dlfcn.h you don't get the macros to mask them, and
34 ** autoconf fails to find them.
36 ** Anybody who wants to use this on SCO needs to have their configure.in
37 ** look for _dlopen() as well as dlopen()
39 #if defined(HAVE_DLOPEN) || defined(HAVE__DLOPEN)
44 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
47 # define RTLD_GLOBAL 0
51 dll_init (CONST char *arg)
57 dll_open (CONST char *fname)
59 return (dll_handle)dlopen (fname, RTLD_LAZY | RTLD_GLOBAL);
63 dll_close (dll_handle h)
65 return dlclose((void *)h);
69 dll_function (dll_handle h, CONST char *n)
71 #ifdef DLSYM_NEEDS_UNDERSCORE
72 char *buf = alloca_array (char, strlen (n) + 2);
74 (void)strcpy(buf + 1, n);
77 return (dll_func)dlsym ((void *)h, n);
81 dll_variable (dll_handle h, CONST char *n)
83 return (dll_var)dlsym ((void *)h, n);
87 dll_error (dll_handle h)
90 return (CONST char *)dlerror ();
92 return "Shared library error";
96 #elif defined(HAVE_SHL_LOAD)
97 /* This is the HP/UX version */
100 dll_init (CONST char *arg)
106 dll_open (CONST char *fname)
108 shl_t h = shl_load (fname, BIND_DEFERRED,0L);
113 hp = (shl_t *)malloc (sizeof (shl_t));
119 return (dll_handle)hp;
123 dll_close (dll_handle h)
125 shl_t hp = *((shl_t *)h);
127 return shl_unload(h);
131 dll_function (dll_handle h, CONST char *n)
135 if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle))
138 return (dll_func)handle;
142 dll_variable (dll_handle h, CONST char *n)
146 if (shl_findsym ((shl_t *)h, n, TYPE_DATA, &handle))
149 return (dll_var)handle;
153 dll_error (dll_handle h)
155 /* #### WTF?! Shouldn't this at least attempt to get strerror or
156 something? --hniksic */
157 return "Generic shared library error";
160 #elif defined(HAVE_INIT_DLD)
163 dll_init (CONST char *arg)
165 char *real_exe = dld_find_executable (arg);
168 rc = dld_init (real_exe);
178 dll_open (CONST char *fname)
180 rc = dld_link (fname);
184 return (dll_handle)1;
188 dll_close (dll_handle h)
190 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
191 ** later on to free the file - you have to remember the filename and
192 ** use that as the unlinker. We should eventually keep a linked list
193 ** of loaded modules and then use the node pointer as the unique id
194 ** for the shared library. Wheeee. But not now.
200 dll_function (dll_handle h, CONST char *n)
202 return dld_get_func(n);
206 dll_variable (dll_handle h, CONST char *n)
208 return dld_get_symbol(n);
210 #elif defined(_WINDOWS) || defined(WIN32)
212 dll_init (CONST char *arg)
218 dll_open (CONST char *fname)
220 return (dll_handle)LoadLibrary (fname);
224 dll_close (dll_handle h)
226 return FreeLibrary (h);
230 dll_function (dll_handle h, CONST char *n)
232 return (dll_func)GetProcAddress (h,n);
236 dll_variable (dll_handle h, CONST char *n)
238 return (dll_func)GetProcAddress (h,n);
242 dll_error (dll_handle h)
244 return "Windows DLL Error";
247 /* Catchall if we don't know about this systems method of dynamic loading */
249 dll_init (CONST char *arg)
255 dll_open (CONST char *fname)
261 dll_close (dll_handle h)
267 dll_function (dll_handle h, CONST char *n)
273 dll_variable (dll_handle h, CONST char *n)
279 dll_error (dll_handle h)
281 return "Shared libraries not implemented on this system";
283 #endif /* System conditionals */
285 #endif /* HAVE_SHLIB */