1 /* GMODULE - GLIB wrapper code for dynamic module loading
2 * Copyright (C) 1998, 2000 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 Lesser 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 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser 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);
66 gchar *msg = g_strdup_printf ("failed to load_add_on(%s): %s",
70 g_module_set_error (msg);
76 return (gpointer) handle;
86 /* Is it always the first one? I'm guessing yes. */
87 status = get_next_image_info (0, &cookie, &info);
89 return (gpointer) info.id;
92 gchar *msg = g_strdup_printf ("failed to get_next_image_info(self): %s",
95 g_module_set_error (msg);
103 _g_module_close (gpointer handle,
109 if (unload_add_on ((image_id) handle) != B_OK)
113 /* Try and get the name of the image. */
114 if (get_image_info ((image_id) handle, &info) != B_OK)
115 name = g_strdup ("unknown");
117 name = g_strdup (info.name);
119 msg = g_strdup_printf ("failed to unload_add_on(%s): %s", name, strerror (status));
120 g_module_set_error (msg);
127 _g_module_symbol (gpointer handle,
128 const gchar *symbol_name)
133 int32 type, name_len;
135 gchar *msg, name[256];
138 id = (image_id) handle;
140 status = get_image_info (id, &info);
143 msg = g_strdup_printf ("failed to get_image_info(): %s", strerror (status));
144 g_module_set_error (msg);
150 l = strlen (symbol_name);
152 type = B_SYMBOL_TYPE_ANY;
154 status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
155 while (status == B_OK)
157 if (p && strncmp (name, symbol_name, l) == 0)
160 if (strcmp (name, "_end") == 0)
162 msg = g_strdup_printf ("unmatched symbol name `%s'", symbol_name);
163 g_module_set_error (msg);
170 type = B_SYMBOL_TYPE_ANY;
172 status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
175 msg = g_strdup_printf ("failed to get_image_symbol(%s): %s", symbol_name, strerror (status));
176 g_module_set_error (msg);
183 _g_module_build_path (const gchar *directory,
184 const gchar *module_name)
186 g_warning ("_g_module_build_path() untested for BeOS!");
188 if (directory && *directory)
190 if (strncmp (module_name, "lib", 3) == 0)
191 return g_strconcat (directory, "/", module_name, NULL);
193 return g_strconcat (directory, "/lib", module_name, ".so", NULL);
195 else if (strncmp (module_name, "lib", 3) == 0)
196 return g_strdup (module_name);
198 return g_strconcat ("lib", module_name, ".so", NULL);