xref: /haiku/src/system/libroot/posix/dlfcn.c (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 2002, Manuel J. Petit. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 
9 
10 #include <libroot_private.h>
11 #include <user_runtime.h>
12 
13 #include <dlfcn.h>
14 #include <string.h>
15 
16 
17 static status_t sStatus;
18 	// Note, this is not thread-safe
19 
20 
21 void *
22 dlopen(char const *name, int mode)
23 {
24 	status_t status;
25 
26 	if (name == NULL)
27 		name = MAGIC_APP_NAME;
28 
29 	status = __gRuntimeLoader->load_add_on(name, mode);
30 	sStatus = status;
31 
32 	if (status < B_OK)
33 		return NULL;
34 
35 	return (void *)status;
36 }
37 
38 
39 void *
40 dlsym(void *handle, char const *name)
41 {
42 	status_t status;
43 	void *location;
44 
45 	status = get_image_symbol((image_id)handle, name, B_SYMBOL_TYPE_ANY, &location);
46 	sStatus = status;
47 
48 	if (status < B_OK)
49 		return NULL;
50 
51 	return location;
52 }
53 
54 
55 int
56 dlclose(void *handle)
57 {
58 	return unload_add_on((image_id)handle);
59 }
60 
61 
62 char *
63 dlerror(void)
64 {
65 	if (sStatus < B_OK)
66 		return strerror(sStatus);
67 
68 	return NULL;
69 }
70 
71