1 /* GMODULE - GLIB wrapper code for dynamic module loading
2 * Copyright (C) 1998 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
34 /* some flags are missing on some systems, so we provide
38 * BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
39 * BIND_DEFERRED - Delay code symbol resolution until actual reference.
42 * BIND_FIRST - Place the library at the head of the symbol search order.
43 * BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all unsatisfied
44 * symbols as fatal. This flag allows binding of unsatisfied code
45 * symbols to be deferred until use.
46 * [Perl: For certain libraries, like DCE, deferred binding often
47 * causes run time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE
48 * still allows unresolved references in situations like this.]
49 * BIND_NOSTART - Do not call the initializer for the shared library when the
50 * library is loaded, nor on a future call to shl_unload().
51 * BIND_VERBOSE - Print verbose messages concerning possible unsatisfied symbols.
53 * hp9000s700/hp9000s800:
54 * BIND_RESTRICTED - Restrict symbols visible by the library to those present at
56 * DYNAMIC_PATH - Allow the loader to dynamically search for the library specified
57 * by the path argument.
60 #define DYNAMIC_PATH 0
61 #endif /* DYNAMIC_PATH */
62 #ifndef BIND_RESTRICTED
63 #define BIND_RESTRICTED 0
64 #endif /* BIND_RESTRICTED */
66 #define OPT_BIND_FLAGS (BIND_NONFATAL | BIND_VERBOSE)
69 /* --- functions --- */
71 _g_module_open (const gchar *file_name,
76 shl_handle = shl_load (file_name,
77 (bind_lazy ? BIND_DEFERRED : BIND_IMMEDIATE) | OPT_BIND_FLAGS, 0);
80 /* the hp-docs say we should better abort() if errno==ENOSYM ;( */
81 g_module_set_error (g_strerror (errno));
84 return (gpointer) shl_handle;
92 shl_handle = PROG_HANDLE;
94 g_module_set_error (g_strerror (errno));
100 _g_module_close (gpointer handle,
105 if (shl_unload ((shl_t) handle) != 0)
106 g_module_set_error (g_strerror (errno));
111 _g_module_symbol (gpointer handle,
112 const gchar *symbol_name)
116 /* should we restrict lookups to TYPE_PROCEDURE?
118 if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
119 handle == NULL || p == NULL)
121 /* the hp-docs say we should better abort() if errno==ENOSYM ;( */
122 g_module_set_error (g_strerror (errno));
129 _g_module_build_path (const gchar *directory,
130 const gchar *module_name)
132 if (directory && *directory)
133 if (strncmp (module_name, "lib", 3) == 0)
134 return g_strconcat (directory, "/", module_name, NULL);
136 return g_strconcat (directory, "/lib", module_name, ".sl", NULL);
137 else if (strncmp (module_name, "lib", 3) == 0)
138 return g_strdup (module_name);
140 return g_strconcat ("lib", module_name, ".sl", NULL);