]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Minor improvements to Windows support
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 7 Sep 2015 18:36:36 +0000 (21:36 +0300)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 13 Sep 2015 12:26:20 +0000 (14:26 +0200)
.gitignore
configure.ac
test/test_util.c
util.c

index cfadd2329ee8d0a53774aa9049ad46d82ee0462a..7896ad11617ad2af2617c9bb49873a2033df7a85 100644 (file)
@@ -1,4 +1,5 @@
 *.a
+*.exe
 *.html
 *.o
 *.xml
index 0be44a40ba3f2fed83bbe37104ca18dfeb4d5a88..af56dca60cee5c771729b1b641fe655f35c30080 100644 (file)
@@ -10,7 +10,7 @@ AC_CONFIG_HEADER(config.h)
 AC_CANONICAL_HOST
 
 case $host in
-    *mingw32* | *cygwin* | *wince* | *mingwce*)
+    *mingw32* | *mingw64* | *cygwin* | *wince* | *mingwce*)
         windows_os=yes
         AC_DEFINE(_WIN32_WINNT,0x0600, Windows Vista or newer is required)
         ;;
index ce9ad44862112ef0fbd894ff21b55c7a9e5c3e55..3842fab3075f9e547c3c0473246b7dea1215ee18 100644 (file)
@@ -60,6 +60,20 @@ TEST(common_dir_prefix_length)
 
 TEST(get_relative_path)
 {
+#ifdef _WIN32
+       CHECK_STR_EQ_FREE2("a", get_relative_path("C:/doesn't matter", "a"));
+       CHECK_STR_EQ_FREE2("a/b", get_relative_path("C:/doesn't matter", "a/b"));
+       CHECK_STR_EQ_FREE2(".", get_relative_path("C:/a", "C:/a"));
+       CHECK_STR_EQ_FREE2("..", get_relative_path("C:/a/b", "C:/a"));
+       CHECK_STR_EQ_FREE2("b", get_relative_path("C:/a", "C:/a/b"));
+       CHECK_STR_EQ_FREE2("b/c", get_relative_path("C:/a", "C:/a/b/c"));
+       CHECK_STR_EQ_FREE2("../c", get_relative_path("C:/a/b", "C:/a/c"));
+       CHECK_STR_EQ_FREE2("../c/d", get_relative_path("C:/a/b", "C:/a/c/d"));
+       CHECK_STR_EQ_FREE2("../../c/d", get_relative_path("C:/a/b/c", "C:/a/c/d"));
+       CHECK_STR_EQ_FREE2("../..", get_relative_path("C:/a/b", "C:/"));
+       CHECK_STR_EQ_FREE2("../../c", get_relative_path("C:/a/b", "C:/c"));
+       CHECK_STR_EQ_FREE2("a/b", get_relative_path("C:/", "C:/a/b"));
+#else
        CHECK_STR_EQ_FREE2("a", get_relative_path("/doesn't matter", "a"));
        CHECK_STR_EQ_FREE2("a/b", get_relative_path("/doesn't matter", "a/b"));
        CHECK_STR_EQ_FREE2(".", get_relative_path("/a", "/a"));
@@ -72,6 +86,7 @@ TEST(get_relative_path)
        CHECK_STR_EQ_FREE2("../..", get_relative_path("/a/b", "/"));
        CHECK_STR_EQ_FREE2("../../c", get_relative_path("/a/b", "/c"));
        CHECK_STR_EQ_FREE2("a/b", get_relative_path("/", "/a/b"));
+#endif
 }
 
 TEST(format_hash_as_string)
diff --git a/util.c b/util.c
index 59cf43575f10704abf9ff98af88dda04feb99be8..739e3aff15a71634ed3f77ec4f5f2f7ec40e432f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1342,13 +1342,20 @@ get_relative_path(const char *from, const char *to)
        const char *p;
        char *result;
 
-       assert(from && from[0] == '/');
+       assert(from && is_absolute_path(from));
        assert(to);
 
-       if (!*to || *to != '/') {
+       if (!*to || !is_absolute_path(to)) {
                return x_strdup(to);
        }
 
+#ifdef _WIN32
+       // Both paths are absolute, drop the drive letters
+       assert(from[0] == to[0]); // Assume the same drive letter
+       from += 2;
+       to += 2;
+#endif
+
        result = x_strdup("");
        common_prefix_len = common_dir_prefix_length(from, to);
        if (common_prefix_len > 0 || !str_eq(from, "/")) {