diff options
author | Denis Krjuchkov <denis@crazydev.net> | 2013-12-05 12:51:01 +0600 |
---|---|---|
committer | Denis Krjuchkov <denis@crazydev.net> | 2013-12-05 15:04:52 +0600 |
commit | 62dc8e4131c4d7784bd500edeaff93ed23807b5f (patch) | |
tree | c70ca62ea615f5929562ea9769ab6d2b1438eba5 /src/fs/Charset.cxx | |
parent | dc554ca61f28a354ee0d9342e60339f7fc75a382 (diff) | |
download | mpd-62dc8e4131c4d7784bd500edeaff93ed23807b5f.tar.gz mpd-62dc8e4131c4d7784bd500edeaff93ed23807b5f.tar.xz mpd-62dc8e4131c4d7784bd500edeaff93ed23807b5f.zip |
fs/Charset.cxx: replace \ with / when converting path to UTF-8 on Windows
Diffstat (limited to 'src/fs/Charset.cxx')
-rw-r--r-- | src/fs/Charset.cxx | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index 3f373a036..dcd291a2d 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -23,9 +23,12 @@ #include "Limits.hxx" #include "system/FatalError.hxx" #include "Log.hxx" +#include "Traits.hxx" #include <glib.h> +#include <algorithm> + #include <assert.h> #include <string.h> @@ -74,13 +77,29 @@ GetFSCharset() return fs_charset.empty() ? "utf-8" : fs_charset.c_str(); } +static inline void FixSeparators(std::string &s) +{ +#ifdef WIN32 + // For whatever reason GCC can't convert constexpr to value reference. + // This leads to link errors when passing separators directly. + auto from = PathTraitsFS::SEPARATOR; + auto to = PathTraitsUTF8::SEPARATOR; + std::replace(s.begin(), s.end(), from, to); +#else + (void)s; +#endif +} + std::string PathToUTF8(const char *path_fs) { assert(path_fs != nullptr); - if (fs_charset.empty()) - return std::string(path_fs); + if (fs_charset.empty()) { + auto result = std::string(path_fs); + FixSeparators(result); + return result; + } GIConv conv = g_iconv_open("utf-8", fs_charset.c_str()); if (conv == reinterpret_cast<GIConv>(-1)) @@ -101,7 +120,9 @@ PathToUTF8(const char *path_fs) if (ret == static_cast<size_t>(-1) || in_left > 0) return std::string(); - return std::string(path_utf8, sizeof(path_utf8) - out_left); + auto result_path = std::string(path_utf8, sizeof(path_utf8) - out_left); + FixSeparators(result_path); + return result_path; } char * |