]> arthur.barton.de Git - netatalk.git/blob - libatalk/util/module.c
Initial revision
[netatalk.git] / libatalk / util / module.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <atalk/util.h>
4
5 static int _mod_dummy;
6
7 #ifdef NO_DLFCN_H
8 #ifdef MACOSX_SERVER
9 #include <mach-o/dyld.h>
10
11 void *mod_open(const char *path)
12 {
13   NSObjectFileImage file;
14
15   if (NSCreateObjectFileImageFromFile(path, &file) != 
16       NSObjectFileImageSuccess)
17     return NULL;
18   return NSLinkModule(file, path, TRUE);
19 }
20
21 void *mod_symbol(void *module, const char *name)
22 {
23    NSSymbol symbol;
24    char *underscore;
25
26    if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
27      return NULL;
28    strcpy(underscore, "_");
29    strcat(underscore, name);
30    symbol = NSLookupAndBindSymbol(underscore);
31    free(underscore);
32
33    return NSAddressOfSymbol(symbol);
34 }
35
36 void mod_close(void *module)
37 {
38   NSUnLinkModule(module, FALSE);
39 }
40 #endif
41
42 #else
43
44 #ifdef DLSYM_PREPEND_UNDERSCORE
45 #include <dlfcn.h>
46
47 void *mod_symbol(void *module, const char *name)
48 {
49    void *symbol;
50    char *underscore;
51
52    if (!module)
53      return NULL;
54
55    if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
56      return NULL;
57
58    strcpy(underscore, "_");
59    strcat(underscore, name);
60    symbol = dlsym(module, underscore);
61    free(underscore);
62
63    return symbol;
64 }
65 #endif /* DLSYM_PREPEND_UNDERSCORE */
66 #endif /* NO_DLFCN */