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 */
46 dll_init (const char *arg)
52 dll_open (const char *fname)
54 return (dll_handle) dlopen (fname, RTLD_NOW);
58 dll_close (dll_handle h)
60 return dlclose ((void *) h);
64 dll_function (dll_handle h, const char *n)
66 #ifdef DLSYM_NEEDS_UNDERSCORE
67 char *buf = alloca_array (char, strlen (n) + 2);
72 return (dll_func) dlsym ((void *) h, n);
76 dll_variable (dll_handle h, const char *n)
78 #ifdef DLSYM_NEEDS_UNDERSCORE
79 char *buf = alloca_array (char, strlen (n) + 2);
84 return (dll_var)dlsym ((void *)h, n);
88 dll_error (dll_handle h)
90 #if defined(HAVE_DLERROR) || defined(dlerror)
91 return (const char *) dlerror ();
92 #elif defined(HAVE__DLERROR)
93 return (const char *) _dlerror();
95 return "Shared library error";
99 #elif defined(HAVE_SHL_LOAD)
100 /* This is the HP/UX version */
103 dll_init (const char *arg)
109 dll_open (const char *fname)
111 /* shl_load will hang hard if passed a NULL fname. */
112 if (fname == NULL) return NULL;
114 return (dll_handle) shl_load (fname, BIND_DEFERRED,0L);
118 dll_close (dll_handle h)
120 return shl_unload ((shl_t) h);
124 dll_function (dll_handle h, const char *n)
128 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
131 return (dll_func) handle;
135 dll_variable (dll_handle h, const char *n)
139 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
142 return (dll_var) handle;
146 dll_error (dll_handle h)
148 /* #### WTF?! Shouldn't this at least attempt to get strerror or
149 something? --hniksic */
150 return "Generic shared library error";
153 #elif defined(HAVE_INIT_DLD)
156 dll_init (const char *arg)
158 char *real_exe = dld_find_executable (arg);
161 rc = dld_init (real_exe);
171 dll_open (const char *fname)
173 rc = dld_link (fname);
177 return (dll_handle) 1;
181 dll_close (dll_handle h)
183 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
184 ** later on to free the file - you have to remember the filename and
185 ** use that as the unlinker. We should eventually keep a linked list
186 ** of loaded modules and then use the node pointer as the unique id
187 ** for the shared library. Wheeee. But not now.
193 dll_function (dll_handle h, const char *n)
195 return dld_get_func (n);
199 dll_variable (dll_handle h, const char *n)
201 return dld_get_symbol (n);
203 #elif defined (WIN32_NATIVE)
205 #define WIN32_LEAN_AND_MEAN
207 #undef WIN32_LEAN_AND_MEAN
210 dll_init (const char *arg)
216 dll_open (const char *fname)
218 return (dll_handle) LoadLibrary (fname);
222 dll_close (dll_handle h)
224 return FreeLibrary (h);
228 dll_function (dll_handle h, const char *n)
230 return (dll_func) GetProcAddress (h, n);
234 dll_variable (dll_handle h, const char *n)
236 return (dll_func) GetProcAddress (h, n);
240 dll_error (dll_handle h)
242 return "Windows DLL Error";
245 /* Catchall if we don't know about this systems method of dynamic loading */
247 dll_init (const char *arg)
253 dll_open (const char *fname)
259 dll_close (dll_handle h)
265 dll_function (dll_handle h, const char *n)
271 dll_variable (dll_handle h, const char *n)
277 dll_error (dll_handle h)
279 return "Shared libraries not implemented on this system";
281 #endif /* System conditionals */
283 #endif /* HAVE_SHLIB */