From 08824da740278bb89b3ccad01b671219e746fec7 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 7 Sep 2015 21:36:36 +0300 Subject: [PATCH] Minor improvements to Windows support --- .gitignore | 1 + configure.ac | 2 +- test/test_util.c | 15 +++++++++++++++ util.c | 11 +++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cfadd2329..7896ad116 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.a +*.exe *.html *.o *.xml diff --git a/configure.ac b/configure.ac index 0be44a40b..af56dca60 100644 --- a/configure.ac +++ b/configure.ac @@ -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) ;; diff --git a/test/test_util.c b/test/test_util.c index ce9ad4486..3842fab30 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -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 59cf43575..739e3aff1 100644 --- 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, "/")) { -- 2.47.2