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