From 7a98a784b272db43f71bd6839eedac2ef7b5fd83 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Apr 2019 14:28:55 +0200 Subject: [PATCH] fs/Features: add macro FS_CHARSET_ALWAYS_UTF8 --- src/fs/AllocatedPath.cxx | 12 ++++++------ src/fs/Features.hxx | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/fs/AllocatedPath.cxx b/src/fs/AllocatedPath.cxx index b2632ac04..0552ccf43 100644 --- a/src/fs/AllocatedPath.cxx +++ b/src/fs/AllocatedPath.cxx @@ -32,24 +32,24 @@ AllocatedPath::~AllocatedPath() noexcept = default; AllocatedPath AllocatedPath::FromUTF8(const char *path_utf8) noexcept { -#if defined(HAVE_FS_CHARSET) || defined(_WIN32) +#ifdef FS_CHARSET_ALWAYS_UTF8 + return FromFS(path_utf8); +#else try { return AllocatedPath(::PathFromUTF8(path_utf8)); } catch (...) { return nullptr; } -#else - return FromFS(path_utf8); #endif } AllocatedPath AllocatedPath::FromUTF8Throw(const char *path_utf8) { -#if defined(HAVE_FS_CHARSET) || defined(_WIN32) - return AllocatedPath(::PathFromUTF8(path_utf8)); -#else +#ifdef FS_CHARSET_ALWAYS_UTF8 return FromFS(path_utf8); +#else + return AllocatedPath(::PathFromUTF8(path_utf8)); #endif } diff --git a/src/fs/Features.hxx b/src/fs/Features.hxx index eb298bc09..1feeaa4a1 100644 --- a/src/fs/Features.hxx +++ b/src/fs/Features.hxx @@ -26,4 +26,11 @@ #define HAVE_FS_CHARSET #endif +#if !defined(HAVE_FS_CHARSET) && !defined(_WIN32) +/** + * Is the filesystem character set hard-coded to UTF-8? + */ +#define FS_CHARSET_ALWAYS_UTF8 +#endif + #endif