Merge pull request #3715 from kumpera/fix-44707
[mono-project.git] / mono / utils / mono-dl-posix.c
blobb48a1831d757df85fc1f2f9c1f6756f91cba9695
1 /*
2 * mono-dl.c: Interface to the dynamic linker
4 * Author:
5 * Mono Team (http://www.mono-project.com)
7 * Copyright 2001-2004 Ximian, Inc.
8 * Copyright 2004-2009 Novell, Inc.
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11 #include <config.h>
13 #ifdef HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
17 #if defined(_POSIX_VERSION)
19 #include "mono/utils/mono-dl.h"
20 #include "mono/utils/mono-embed.h"
21 #include "mono/utils/mono-path.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <glib.h>
28 #include <dlfcn.h>
30 #if !defined (TARGET_MACH)
31 const char *
32 mono_dl_get_so_prefix (void)
34 return "lib";
36 const char **
37 mono_dl_get_so_suffixes (void)
39 static const char *suffixes[] = {
40 ".so",
41 "",
43 return suffixes;
46 int
47 mono_dl_get_executable_path (char *buf, int buflen)
49 return readlink ("/proc/self/exe", buf, buflen - 1);
52 const char*
53 mono_dl_get_system_dir (void)
55 return NULL;
58 #endif
60 void *
61 mono_dl_open_file (const char *file, int flags)
63 #ifdef PLATFORM_ANDROID
64 /* Bionic doesn't support NULL filenames */
65 if (!file)
66 return NULL;
67 #endif
68 return dlopen (file, flags);
71 void
72 mono_dl_close_handle (MonoDl *module)
74 dlclose (module->handle);
77 void*
78 mono_dl_lookup_symbol (MonoDl *module, const char *name)
80 return dlsym (module->handle, name);
83 int
84 mono_dl_convert_flags (int flags)
86 int lflags = flags & MONO_DL_LOCAL? 0: RTLD_GLOBAL;
88 if (flags & MONO_DL_LAZY)
89 lflags |= RTLD_LAZY;
90 else
91 lflags |= RTLD_NOW;
92 return lflags;
95 char*
96 mono_dl_current_error_string (void)
98 return g_strdup (dlerror ());
101 #endif