Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / mono-dl-posix.c
1 /**
2  * \file
3  * Interface to the dynamic linker
4  *
5  * Author:
6  *    Mono Team (http://www.mono-project.com)
7  *
8  * Copyright 2001-2004 Ximian, Inc.
9  * Copyright 2004-2009 Novell, Inc.
10  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12 #include <config.h>
13
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17
18 #if defined(_POSIX_VERSION) && !defined (HOST_WASM)
19
20 #include "mono/utils/mono-dl.h"
21 #include "mono/utils/mono-embed.h"
22 #include "mono/utils/mono-path.h"
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <string.h>
28 #include <glib.h>
29 #include <dlfcn.h>
30
31 #if !defined (TARGET_MACH)
32 const char *
33 mono_dl_get_so_prefix (void)
34 {
35         return "lib";
36 }
37 const char **
38 mono_dl_get_so_suffixes (void)
39 {
40         static const char *suffixes[] = {
41                 ".so",
42                 "",
43         };
44         return suffixes;
45 }
46
47 int
48 mono_dl_get_executable_path (char *buf, int buflen)
49 {
50         return readlink ("/proc/self/exe", buf, buflen - 1);
51 }
52
53 const char*
54 mono_dl_get_system_dir (void)
55 {
56         return NULL;
57 }
58
59 #endif
60
61 void *
62 mono_dl_open_file (const char *file, int flags)
63 {
64 #ifdef HOST_ANDROID
65         /* Bionic doesn't support NULL filenames */
66         if (!file)
67                 return NULL;
68 #endif
69         return dlopen (file, flags);
70 }
71
72 void
73 mono_dl_close_handle (MonoDl *module)
74 {
75         dlclose (module->handle);
76 }
77
78 void*
79 mono_dl_lookup_symbol (MonoDl *module, const char *name)
80 {
81         return dlsym (module->handle, name);
82 }
83
84 int
85 mono_dl_convert_flags (int flags)
86 {
87         int lflags = flags & MONO_DL_LOCAL? 0: RTLD_GLOBAL;
88
89         if (flags & MONO_DL_LAZY)
90                 lflags |= RTLD_LAZY;
91         else
92                 lflags |= RTLD_NOW;
93         return lflags;
94 }
95
96 char*
97 mono_dl_current_error_string (void)
98 {
99         return g_strdup (dlerror ());
100 }
101
102 #endif