aboutsummaryrefslogtreecommitdiff
path: root/butl/path.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-02-10 16:10:33 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-02-13 12:55:34 +0300
commit31e91691e815074ebdb49d258967e2b2a0bfc965 (patch)
tree1739e815c312b40fa9a8c64b7b144cf60d4c28bb /butl/path.cxx
parent66ca47f856cc04774cbe07dc67e2e099e5d527f3 (diff)
Add path_entry(), fixes for path
Diffstat (limited to 'butl/path.cxx')
-rw-r--r--butl/path.cxx23
1 files changed, 21 insertions, 2 deletions
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<char>::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];