2009-10-22 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / utils / mono-path.c
index cc3623f0ff1d476fc9f2b23cf3dcf341a0468d3a..99e82ce71ae337ebee7efad7fead01fc6d7ec23d 100644 (file)
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 /* This is only needed for the mono_path_canonicalize code, MAXSYMLINKS, could be moved */
+#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
+#endif
 
 #include "mono-path.h"
 
+/* Embedded systems lack MAXSYMLINKS */
+#ifndef MAXSYMLINKS
+#define MAXSYMLINKS 3
+#endif
+
 /* Resolves '..' and '.' references in a path. If the path provided is relative,
  * it will be relative to the current directory */
 gchar *
@@ -34,6 +44,9 @@ mono_path_canonicalize (const char *path)
                g_free (tmpdir);
        }
 
+#ifdef PLATFORM_WIN32
+       g_strdelimit (abspath, "/", '\\');
+#endif
        abspath = g_strreverse (abspath);
 
        backc = 0;
@@ -59,6 +72,11 @@ mono_path_canonicalize (const char *path)
                lastpos = pos + 1;
                pos = strchr (lastpos, G_DIR_SEPARATOR);
        }
+
+#ifdef PLATFORM_WIN32 /* For UNC paths the first '\' is removed. */
+       if (*(lastpos-1) == G_DIR_SEPARATOR && *(lastpos-2) == G_DIR_SEPARATOR)
+               lastpos = lastpos-1;
+#endif
        
        if (dest != lastpos) strcpy (dest, lastpos);
        return g_strreverse (abspath);
@@ -71,7 +89,7 @@ mono_path_canonicalize (const char *path)
 gchar *
 mono_path_resolve_symlinks (const char *path)
 {
-#if PLATFORM_WIN32
+#if defined(PLATFORM_NO_SYMLINKS)
        return mono_path_canonicalize (path);
 #else
        char *p, *concat, *dir;