1 /* GMODULE - GLIB wrapper code for dynamic module loading
2 * Copyright (C) 1998 Tim Janik
4 * BeOS GMODULE implementation
5 * Copyright (C) 1999 Richard Offer and Shawn T. Amundson (amundson@gtk.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include <be/kernel/image.h> /* image (aka DSO) handling functions... */
30 * The BeOS doesn't use the same symantics as Unix's dlopen....
35 #endif /* RTLD_GLOBAL */
38 #endif /* RTLD_LAZY */
47 * You can load the same DSO more than once, in which case you'll have
48 * different image_id's. While this means that we don't have to worry about
49 * reference counts, it could lead to problems in the future....
56 /* --- functions --- */
58 _g_module_open (const gchar *file_name,
63 handle = load_add_on (file_name);
65 g_module_set_error (g_strdup_printf("failed to load_add_on(%s), reason: %s",
66 (gchar *) file_name, strerror(handle)));
70 return (gpointer) handle;
80 /* Is it always the first one? I'm guessing yes. */
81 if ((status = get_next_image_info(0, &cookie, &info)) == B_OK)
82 return (gpointer) info.id;
85 g_module_set_error (g_strdup_printf("get_next_image_info() for self failed, reason: %s", strerror(status)));
91 _g_module_close (gpointer handle,
97 if (unload_add_on((image_id) handle) != B_OK)
99 /* Try and get the name of the image. */
100 if (get_image_info((image_id) handle, &info) != B_OK)
101 name = g_strdup("(unknown)");
103 name = g_strdup (info.name);
105 g_module_set_error (g_strdup_printf("failed to unload_add_on(%s)",
112 _g_module_symbol (gpointer handle,
113 const gchar *symbol_name)
124 id = (image_id) handle;
126 if ((status = get_image_info(id, &info)) != B_OK)
128 g_module_set_error (g_strdup_printf("failed get_image_info(), reason: %s", strerror(status)));
133 type = B_SYMBOL_TYPE_ANY;
135 while ((status = get_nth_image_symbol(id, n, name, &name_len, &type, (void **)&p)) == B_OK)
137 if (!strncmp (name, symbol_name, strlen(symbol_name)))
142 if (!strcmp (name, "_end"))
144 g_module_set_error (g_strdup_printf("g_module_symbol(): no symbol matching '%s'", symbol_name));
149 type = B_SYMBOL_TYPE_ANY;
153 g_module_set_error (g_strdup_printf("failed get_image_symbol(%s), reason: %s", symbol_name, strerror(status)));
158 _g_module_build_path (const gchar *directory,
159 const gchar *module_name)
161 printf("WARNING: _g_module_build_path() untested!\n");
162 if (directory && *directory) {
163 if (strncmp (module_name, "lib", 3) == 0)
164 return g_strconcat (directory, "/", module_name, NULL);
166 return g_strconcat (directory, "/lib", module_name, ".so", NULL);
167 } else if (strncmp (module_name, "lib", 3) == 0)
168 return g_strdup (module_name);
170 return g_strconcat ("lib", module_name, ".so", NULL);