fs/Traits: enable _UNICODE on Windows

Use wchar_t for everything on Windows.  Solves a lot of filesystem
charset problems.
This commit is contained in:
Max Kellermann
2015-02-25 16:01:46 +01:00
parent 1da0956331
commit 65ff72cdf8
8 changed files with 114 additions and 5 deletions

View File

@@ -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;