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
32 /* This whole file is conditional upon HAVE_DLL */
35 /* Thankfully, most systems follow the ELFish dlopen() method.
36 ** HAVE__DLOPEN is lame, but SCO has their dl* functions as _dl*, and
37 ** unless you include dlfcn.h you don't get the macros to mask them, and
38 ** autoconf fails to find them.
40 ** Anybody who wants to use this on SCO needs to have their configure.in
41 ** look for _dlopen() as well as dlopen()
43 #if defined(HAVE_DLOPEN) || defined(HAVE__DLOPEN)
48 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
51 # define RTLD_GLOBAL 0
55 dll_init (CONST char *arg)
61 dll_open (CONST char *fname)
63 return (dll_handle)dlopen (fname, RTLD_LAZY | RTLD_GLOBAL);
67 dll_close (dll_handle h)
69 return dlclose((void *)h);
73 dll_function (dll_handle h, CONST char *n)
75 #ifdef DLSYM_NEEDS_UNDERSCORE
76 char *buf = alloca_array (char, strlen (n) + 2);
78 (void)strcpy(buf + 1, n);
81 return (dll_func)dlsym ((void *)h, n);
85 dll_variable (dll_handle h, CONST char *n)
87 return (dll_var)dlsym ((void *)h, n);
91 dll_error (dll_handle h)
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_t h = shl_load (fname, BIND_DEFERRED,0L);
117 hp = (shl_t *)malloc (sizeof (shl_t));
123 return (dll_handle)hp;
127 dll_close (dll_handle h)
129 shl_t hp = *((shl_t *)h);
131 return shl_unload(h);
135 dll_function (dll_handle h, CONST char *n)
139 if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle))
142 return (dll_func)handle;
146 dll_variable (dll_handle h, CONST char *n)
150 if (shl_findsym ((shl_t *)h, n, TYPE_DATA, &handle))
153 return (dll_var)handle;
157 dll_error (dll_handle h)
159 /* #### WTF?! Shouldn't this at least attempt to get strerror or
160 something? --hniksic */
161 return "Generic shared library error";
164 #elif defined(HAVE_INIT_DLD)
167 dll_init (CONST char *arg)
169 char *real_exe = dld_find_executable (arg);
172 rc = dld_init (real_exe);
182 dll_open (CONST char *fname)
184 rc = dld_link (fname);
188 return (dll_handle)1;
192 dll_close (dll_handle h)
194 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
195 ** later on to free the file - you have to remember the filename and
196 ** use that as the unlinker. We should eventually keep a linked list
197 ** of loaded modules and then use the node pointer as the unique id
198 ** for the shared library. Wheeee. But not now.
204 dll_function (dll_handle h, CONST char *n)
206 return dld_get_func(n);
210 dll_variable (dll_handle h, CONST char *n)
212 return dld_get_symbol(n);
214 #elif defined(_WINDOWS) || defined(WIN32)
216 dll_init (CONST char *arg)
222 dll_open (CONST char *fname)
224 return (dll_handle)LoadLibrary (fname);
228 dll_close (dll_handle h)
230 return FreeLibrary (h);
234 dll_function (dll_handle h, CONST char *n)
236 return (dll_func)GetProcAddress (h,n);
240 dll_variable (dll_handle h, CONST char *n)
242 return (dll_func)GetProcAddress (h,n);
246 dll_error (dll_handle h)
248 return "Windows DLL Error";
251 /* Catchall if we don't know about this systems method of dynamic loading */
253 dll_init (CONST char *arg)
259 dll_open (CONST char *fname)
265 dll_close (dll_handle h)
271 dll_function (dll_handle h, CONST char *n)
277 dll_variable (dll_handle h, CONST char *n)
283 dll_error (dll_handle h)
285 return "Shared libraries not implemented on this system";
287 #endif /* System conditionals */
289 #endif /* HAVE_SHLIB */