diff options
author | Max Kellermann <max@duempel.org> | 2015-06-23 13:09:36 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-06-23 13:20:11 +0200 |
commit | d551d40886f50f83f5893891e8ed15b2dd786cf6 (patch) | |
tree | c7972b8665de4053b2fc3f29ec769c96776e4345 | |
parent | aecfcaa8a2b646f6a2503ba5b2b647c89d53e405 (diff) | |
download | mpd-d551d40886f50f83f5893891e8ed15b2dd786cf6.tar.gz mpd-d551d40886f50f83f5893891e8ed15b2dd786cf6.tar.xz mpd-d551d40886f50f83f5893891e8ed15b2dd786cf6.zip |
fs/NarrowPath: use the WideCharToMultiByte() wrapper
Diffstat (limited to '')
-rw-r--r-- | src/fs/NarrowPath.hxx | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/fs/NarrowPath.hxx b/src/fs/NarrowPath.hxx index ad310cd5c..433a9c1cd 100644 --- a/src/fs/NarrowPath.hxx +++ b/src/fs/NarrowPath.hxx @@ -25,7 +25,11 @@ #include "util/Macros.hxx" #ifdef _UNICODE +#include "lib/icu/Win32.hxx" +#include "util/AllocatedString.hxx" #include <windows.h> +#else +#include "util/StringPointer.hxx" #endif /** @@ -34,35 +38,33 @@ * that accepts only "const char *". */ class NarrowPath { - typedef char value_type; - typedef const char *const_pointer; - #ifdef _UNICODE - char value[PATH_MAX]; + typedef AllocatedString<> Value; #else - const_pointer value; + typedef StringPointer<> Value; #endif + typedef typename Value::const_pointer const_pointer; + + Value value; public: #ifdef _UNICODE - explicit NarrowPath(Path _path) { - auto result = WideCharToMultiByte(CP_ACP, 0, - _path.c_str(), -1, - value, ARRAY_SIZE(value), - nullptr, nullptr); - if (result < 0) - value[0] = 0; + explicit NarrowPath(Path _path) + :value(WideCharToMultiByte(CP_ACP, _path.c_str())) { + if (value.IsNull()) + /* fall back to empty string */ + value = Value::Empty(); } #else explicit NarrowPath(Path _path):value(_path.c_str()) {} #endif operator const_pointer() const { - return value; + return c_str(); } const_pointer c_str() const { - return value; + return value.c_str(); } }; |