Moved the File selection dialog
[grace.git] / src / dlmodule.c
blobb128c7fa10ca58d0aef5d24f145989ee846643bf
1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
3 *
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5 *
6 * Copyright (c) 1991-95 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-99 Grace Development Team
8 *
9 * Maintained by Evgeny Stambulchik
12 * All Rights Reserved
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
35 * - VMS ??
38 #include <config.h>
40 #if defined(HAVE_DLOPEN)
41 # include <dlfcn.h>
42 #endif
44 #if defined(HAVE_SHL_LOAD)
45 # include <dl.h>
46 #endif
48 #include <string.h>
50 #include "dlmodule.h"
52 #include "defines.h"
53 #include "utils.h"
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)
60 #if defined(HAVE_DL)
62 int dlflag;
63 void *handle;
64 char *error;
65 symtab_entry newkey;
66 int retval;
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) {
76 dlflag = RTLD_LAZY;
77 } else {
78 dlflag = RTLD_NOW;
80 # else
81 dlflag = 1;
82 # endif
84 handle = (void *) dlopen (fname, dlflag);
85 if (!handle) {
86 errmsg ((char *) dlerror());
87 return RETURN_FAILURE;
90 newkey.data = dlsym(handle, dl_function);
91 if ((error = (char *) dlerror()) != NULL) {
92 errmsg(error);
93 dlclose(handle);
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;
103 } else {
104 dlflag = BIND_IMMEDIATE;
107 handle = (void *) shl_load (fname, dlflag, 0L);
108 if (!handle) {
109 #if defined(HAVE_STRERROR)
110 errmsg(strerror(errno));
111 #else
112 # if defined(HAVE_SYS_ERRLIST_DECL)
113 errmsg(sys_errlist[errno]);
114 # else
115 errmsg("DL module initialization failed");
116 # endif
117 #endif
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));
124 #else
125 # if defined(HAVE_SYS_ERRLIST_DECL)
126 errmsg(sys_errlist[errno]);
127 # else
128 errmsg("Error while resolving symbol");
129 # endif
130 #endif
131 shl_unload(handle);
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);
141 xfree(newkey.s);
142 return retval;
144 #else /* no support for DL */
145 errmsg("No support for DL modules on your OS");
146 return RETURN_FAILURE;
147 #endif