From 31e91691e815074ebdb49d258967e2b2a0bfc965 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 10 Feb 2017 16:10:33 +0300 Subject: Add path_entry(), fixes for path --- butl/path.cxx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'butl/path.cxx') diff --git a/butl/path.cxx b/butl/path.cxx index bfae61b..9947bbe 100644 --- a/butl/path.cxx +++ b/butl/path.cxx @@ -81,7 +81,18 @@ namespace butl current_directory (string_type const& s) { #ifdef _WIN32 - if (_chdir (s.c_str ()) != 0) + // A path like 'C:', while being a root path in our terminology, is not as + // such for Windows, that maintains current directory for each drive, and + // so "change current directory to C:" means "change the process current + // directory to current directory on the C drive". Changing it to the root + // one of the drive requires the trailing directory separator to be + // present. + // + string_type const& d (!root (s) + ? s + : string_type (s + directory_separator)); + + if (_chdir (d.c_str ()) != 0) throw system_error (errno, system_category ()); #else if (chdir (s.c_str ()) != 0) @@ -248,7 +259,15 @@ namespace butl current_directory (string_type const& s) { #ifdef _WIN32 - if (_wchdir (s.c_str ()) != 0) + // Append the trailing directory separator for the root directory (read + // the comment in path_traits::current_directory() for + // justification). + // + string_type const& d (!root (s) + ? s + : string_type (s + directory_separator)); + + if (_wchdir (d.c_str ()) != 0) throw system_error (errno, system_category ()); #else char ns[PATH_MAX + 1]; -- cgit v1.1