]> arthur.barton.de Git - netatalk.git/blob - libatalk/util/module.c
Joe Clarke's fix for linux/quota.h checking, removed NO_DLFCN_H define
[netatalk.git] / libatalk / util / module.c
1 /*
2  * $Id: module.c,v 1.3 2001-06-20 14:51:13 rufustfirefly 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 static int _mod_dummy;
14
15 #ifndef HAVE_DLFCN_H
16 #ifdef MACOSX_SERVER
17 #include <mach-o/dyld.h>
18
19 void *mod_open(const char *path)
20 {
21   NSObjectFileImage file;
22
23   if (NSCreateObjectFileImageFromFile(path, &file) != 
24       NSObjectFileImageSuccess)
25     return NULL;
26   return NSLinkModule(file, path, TRUE);
27 }
28
29 void *mod_symbol(void *module, const char *name)
30 {
31    NSSymbol symbol;
32    char *underscore;
33
34    if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
35      return NULL;
36    strcpy(underscore, "_");
37    strcat(underscore, name);
38    symbol = NSLookupAndBindSymbol(underscore);
39    free(underscore);
40
41    return NSAddressOfSymbol(symbol);
42 }
43
44 void mod_close(void *module)
45 {
46   NSUnLinkModule(module, FALSE);
47 }
48 #endif /* MACOSX_SERVER */
49
50 #else /* HAVE_DLFCN_H */
51
52 #ifdef DLSYM_PREPEND_UNDERSCORE
53 #include <dlfcn.h>
54
55 void *mod_symbol(void *module, const char *name)
56 {
57    void *symbol;
58    char *underscore;
59
60    if (!module)
61      return NULL;
62
63    if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
64      return NULL;
65
66    strcpy(underscore, "_");
67    strcat(underscore, name);
68    symbol = dlsym(module, underscore);
69    free(underscore);
70
71    return symbol;
72 }
73 #endif /* DLSYM_PREPEND_UNDERSCORE */
74 #endif /* HAVE_DLFCN_H */