Skip to content

Commit

Permalink
Minor improvements to Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov authored and jrosdahl committed Sep 13, 2015
1 parent 3f2c71b commit 08824da
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.a
*.exe
*.html
*.o
*.xml
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
Expand Down
15 changes: 15 additions & 0 deletions test/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")) {
Expand Down

0 comments on commit 08824da

Please sign in to comment.