From 65ff72cdf8d3fc8664893b55ca47fca284f34d87 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Feb 2015 16:01:46 +0100 Subject: fs/Traits: enable _UNICODE on Windows Use wchar_t for everything on Windows. Solves a lot of filesystem charset problems. --- src/fs/NarrowPath.hxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/fs/NarrowPath.hxx') diff --git a/src/fs/NarrowPath.hxx b/src/fs/NarrowPath.hxx index 2088f9359..ad310cd5c 100644 --- a/src/fs/NarrowPath.hxx +++ b/src/fs/NarrowPath.hxx @@ -22,6 +22,11 @@ #include "check.h" #include "Path.hxx" +#include "util/Macros.hxx" + +#ifdef _UNICODE +#include +#endif /** * A path name that uses the regular (narrow) "char". This is used to @@ -32,10 +37,25 @@ class NarrowPath { typedef char value_type; typedef const char *const_pointer; +#ifdef _UNICODE + char value[PATH_MAX]; +#else const_pointer value; +#endif 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; + } +#else explicit NarrowPath(Path _path):value(_path.c_str()) {} +#endif operator const_pointer() const { return value; -- cgit v1.2.3