adb: fix mkdirs / adb pull with relative paths, fix win32 issues

Relative paths were being prefixed with OS_PATH_SEPARATOR on unix and
win32 causing adb to incorrectly try to make directories at the root.
Plus, absolute paths didn't work on win32 (C: got prefixed into \C:).

This fix is to use dirname (available on win32 via mingw's crt) to do
the messy parsing.

I added a test for the relative path case.

Change-Id: Ibb0a4a8ec7756351d252a4d267122ab18e182858
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp
index 9c9f85c..34b54e7 100644
--- a/adb/adb_utils_test.cpp
+++ b/adb/adb_utils_test.cpp
@@ -186,10 +186,19 @@
   EXPECT_FALSE(parse_host_and_port("1.2.3.4:65536", &canonical_address, &host, &port, &error));
 }
 
+void test_mkdirs(const std::string basepath) {
+  EXPECT_TRUE(mkdirs(basepath));
+  EXPECT_NE(-1, adb_creat(basepath.c_str(), 0600));
+  EXPECT_FALSE(mkdirs(basepath + "/subdir/"));
+}
+
 TEST(adb_utils, mkdirs) {
   TemporaryDir td;
-  std::string path = std::string(td.path) + "/dir/subdir/file";
-  EXPECT_TRUE(mkdirs(path));
-  EXPECT_NE(-1, adb_creat(path.c_str(), 0600));
-  EXPECT_FALSE(mkdirs(path + "/subdir/"));
+
+  // Absolute paths.
+  test_mkdirs(std::string(td.path) + "/dir/subdir/file");
+
+  // Relative paths.
+  ASSERT_EQ(0, chdir(td.path)) << strerror(errno);
+  test_mkdirs(std::string("relative/subrel/file"));
 }