2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 1991-95 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-99 Grace Development Team
9 * Maintained by Evgeny Stambulchik
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 * dlmodule.c - DLL stuff for Grace
31 * The following interfaces are supported:
32 * + dlopen() (Linux, SunOS, Solaris, OSF, IRIX, AIX-4, UnixWare, ...)
33 * + shl_load() (HP/UX)
34 * + AIX-3 - there is a free dlopen() emulation library
40 #if defined(HAVE_DLOPEN)
44 #if defined(HAVE_SHL_LOAD)
55 int dl_load_fast
= TRUE
; /* controls type of DL module load */
56 /* TODO: make it tunable through a command */
58 int load_module(char *fname
, char *dl_function
, char *dl_key
, int dl_type
)
68 if ((dl_type
< 0) || (dl_key
== NULL
) || (dl_function
== NULL
)) {
69 errmsg("Improper call to load_module()");
70 return RETURN_FAILURE
;
73 #if defined(HAVE_DLOPEN)
74 # if defined(HAVE_RTLD_NOW)
75 if (dl_load_fast
== TRUE
) {
84 handle
= (void *) dlopen (fname
, dlflag
);
86 errmsg ((char *) dlerror());
87 return RETURN_FAILURE
;
90 newkey
.data
= dlsym(handle
, dl_function
);
91 if ((error
= (char *) dlerror()) != NULL
) {
94 return RETURN_FAILURE
;
97 #endif /* end dlopen interface */
99 #if defined(HAVE_SHL_LOAD)
101 if (dl_load_fast
== TRUE
) {
102 dlflag
= BIND_DEFERRED
;
104 dlflag
= BIND_IMMEDIATE
;
107 handle
= (void *) shl_load (fname
, dlflag
, 0L);
109 #if defined(HAVE_STRERROR)
110 errmsg(strerror(errno
));
112 # if defined(HAVE_SYS_ERRLIST_DECL)
113 errmsg(sys_errlist
[errno
]);
115 errmsg("DL module initialization failed");
118 return RETURN_FAILURE
;
121 if (shl_findsym(handle
, dl_function
, TYPE_UNDEFINED
, &newkey
.data
) != NULL
) {
122 #if defined(HAVE_STRERROR)
123 errmsg(strerror(errno
));
125 # if defined(HAVE_SYS_ERRLIST_DECL)
126 errmsg(sys_errlist
[errno
]);
128 errmsg("Error while resolving symbol");
132 return RETURN_FAILURE
;
135 #endif /* end shl_load interface */
137 newkey
.type
= dl_type
;
138 newkey
.s
= copy_string(NULL
, dl_key
);
140 retval
= addto_symtab(newkey
);
144 #else /* no support for DL */
145 errmsg("No support for DL modules on your OS");
146 return RETURN_FAILURE
;