Merge pull request #2819 from BrzVlad/fix-major-log
[mono.git] / mono / utils / mono-dl.c
index 7adfa9dec798cd1e73288c04ad7f9e17aaa694ce..43116130309eec7195e24a87f8d39e10e544dbce 100644 (file)
@@ -6,6 +6,7 @@
  *
  * Copyright 2001-2004 Ximian, Inc.
  * Copyright 2004-2009 Novell, Inc.
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 #include "config.h"
 #include "mono/utils/mono-dl.h"
@@ -55,7 +56,7 @@ read_string (char *p, FILE *file)
                if (!endp)
                        return NULL;
                *endp = 0;
-               return g_memdup (startp, (endp - startp) + 1);
+               return (char *) g_memdup (startp, (endp - startp) + 1);
        }
        if (*p == 0)
                return NULL;
@@ -63,7 +64,7 @@ read_string (char *p, FILE *file)
        while (*p && !isspace (*p))
                ++p;
        *p = 0;
-       return g_memdup (startp, (p - startp) + 1);
+       return (char *) g_memdup (startp, (p - startp) + 1);
 }
 
 /*
@@ -139,7 +140,7 @@ mono_dl_open (const char *name, int flags, char **error_msg)
        if (error_msg)
                *error_msg = NULL;
 
-       module = malloc (sizeof (MonoDl));
+       module = (MonoDl *) malloc (sizeof (MonoDl));
        if (!module) {
                if (error_msg)
                        *error_msg = g_strdup ("Out of memory");
@@ -401,28 +402,35 @@ mono_dl_open_runtime_lib (const char* lib_name, int flags, char **error_msg)
        if (binl != -1) {
                char *base;
                char *resolvedname, *name;
+               char *baseparent = NULL;
                buf [binl] = 0;
                resolvedname = mono_path_resolve_symlinks (buf);
                base = g_path_get_dirname (resolvedname);
                name = g_strdup_printf ("%s/.libs", base);
                runtime_lib = try_load (lib_name, name, flags, error_msg);
                g_free (name);
+               if (!runtime_lib)
+                       baseparent = g_path_get_dirname (base);
                if (!runtime_lib) {
-                       char *newbase = g_path_get_dirname (base);
-                       name = g_strdup_printf ("%s/lib", newbase);
+                       name = g_strdup_printf ("%s/lib", baseparent);
                        runtime_lib = try_load (lib_name, name, flags, error_msg);
                        g_free (name);
                }
 #ifdef __MACH__
                if (!runtime_lib) {
-                       char *newbase = g_path_get_dirname (base);
-                       name = g_strdup_printf ("%s/Libraries", newbase);
+                       name = g_strdup_printf ("%s/Libraries", baseparent);
                        runtime_lib = try_load (lib_name, name, flags, error_msg);
                        g_free (name);
                }
 #endif
+               if (!runtime_lib) {
+                       name = g_strdup_printf ("%s/profiler/.libs", baseparent);
+                       runtime_lib = try_load (lib_name, name, flags, error_msg);
+                       g_free (name);
+               }
                g_free (base);
                g_free (resolvedname);
+               g_free (baseparent);
        }
        if (!runtime_lib)
                runtime_lib = try_load (lib_name, NULL, flags, error_msg);