Skip to content

Commit

Permalink
Avoid using boost::filesystem w/string conversions on Windows
Browse files Browse the repository at this point in the history
Converting from wstring to string (or vice versa) with boost::filesystem
requires Filesystem to be compiled. However if these conversions are
avoided, then boost::filesystem will not be needed by downstream
projects.
  • Loading branch information
achow101 committed Jan 21, 2022
1 parent d231979 commit 42d30d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/boost/process/detail/windows/basic_cmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ struct exe_cmd_init : handler_base_ext
return exe_cmd_init<Char>(std::move(sh), std::move(args_));
}

static std:: string get_shell(char) {return shell(). string(codecvt()); }
static std:: string get_shell(char) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.to_bytes(shell().wstring(codecvt()));
}
static std::wstring get_shell(wchar_t) {return shell().wstring(codecvt());}

static exe_cmd_init<Char> cmd_shell(string_type&& cmd)
Expand Down
4 changes: 2 additions & 2 deletions include/boost/process/detail/windows/shell_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ inline boost::filesystem::path shell_path()
throw_last_error("GetSystemDirectory() failed");

boost::filesystem::path p = sysdir;
return p / "cmd.exe";
return p += L"\\cmd.exe";
}

inline boost::filesystem::path shell_path(std::error_code &ec) noexcept
Expand All @@ -43,7 +43,7 @@ inline boost::filesystem::path shell_path(std::error_code &ec) noexcept
{
ec.clear();
p = sysdir;
p /= "cmd.exe";
p += L"\\cmd.exe";
}
return p;
}
Expand Down

0 comments on commit 42d30d1

Please sign in to comment.