summaryrefslogtreecommitdiff
path: root/src/fs/NarrowPath.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-02-25 16:01:46 +0100
committerMax Kellermann <max@duempel.org>2015-03-05 10:15:10 +0100
commit65ff72cdf8d3fc8664893b55ca47fca284f34d87 (patch)
tree766eca97378aa4567d7e55aba24c4a785f956f9d /src/fs/NarrowPath.hxx
parent1da09563310a666095e93d3b4fdc5556a8a7c534 (diff)
fs/Traits: enable _UNICODE on Windows
Use wchar_t for everything on Windows. Solves a lot of filesystem charset problems.
Diffstat (limited to 'src/fs/NarrowPath.hxx')
-rw-r--r--src/fs/NarrowPath.hxx20
1 files changed, 20 insertions, 0 deletions
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 <windows.h>
+#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;