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