ff7028555c18d05f5a310a58a5caa2739e7cd4c0
[mono.git] / mono / utils / mono-dl-darwin.c
1 /*
2  * mono-dl.c: Interface to the dynamic linker
3  *
4  * Author:
5  *    Mono Team (http://www.mono-project.com)
6  *
7  * Copyright 2001-2004 Ximian, Inc.
8  * Copyright 2004-2009 Novell, Inc.
9  */
10 #include <config.h>
11
12 #if defined (TARGET_MACH)
13
14 #include "mono/utils/mono-dl.h"
15 #include "mono/utils/mono-embed.h"
16 #include "mono/utils/mono-path.h"
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <ctype.h>
21 #include <string.h>
22 #include <glib.h>
23 #include <dlfcn.h>
24 #include <unistd.h>
25 #include <mach-o/dyld.h>
26
27 const char *
28 mono_dl_get_so_prefix (void)
29 {
30         return "lib";
31 }
32 const char **
33 mono_dl_get_so_suffixes (void)
34 {
35         static const char *suffixes[] = {
36                 ".dylib",
37                 ".so",
38                 ".bundle",
39                 "",
40         };
41         return suffixes;
42 }
43
44 int
45 mono_dl_get_executable_path (char *buf, int buflen)
46 {
47         uint32_t bsize = buflen;
48         if (_NSGetExecutablePath (buf, &bsize) == 0)
49                 return strlen (buf);
50         return -1;
51 }
52
53 const char*
54 mono_dl_get_system_dir (void)
55 {
56 #ifdef TARGET_IOS
57         /* IOS9 can't load system libraries using relative paths, i.e. 'libc' doesn't work, but '/usr/lib/libc' does. */
58         return "/usr/lib";
59 #else
60         return NULL;
61 #endif
62 }
63
64 #endif