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