From fd2c6b8a4b059bd810ca8511fa8f66001843284c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 29 Nov 2014 22:33:30 +0100 Subject: fs/Charset: return Error on SetFSCharset() failure Don't abort the process, let the caller decide instead. --- src/fs/Charset.cxx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/fs/Charset.cxx') diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index abf4d8287..113f04cc8 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -21,9 +21,10 @@ #include "Charset.hxx" #include "Domain.hxx" #include "Limits.hxx" -#include "system/FatalError.hxx" #include "Log.hxx" #include "Traits.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #ifdef HAVE_GLIB #include @@ -36,6 +37,8 @@ #ifdef HAVE_GLIB +static constexpr Domain convert_domain("convert"); + /** * Maximal number of bytes required to represent path name in UTF-8 * (including nul-terminator). @@ -50,29 +53,37 @@ static std::string fs_charset; gcc_pure static bool -IsSupportedCharset(const char *charset) +CheckCharset(const char *charset, Error &error) { /* convert a space to check if the charset is valid */ - char *test = g_convert(" ", 1, charset, "UTF-8", nullptr, nullptr, nullptr); - if (test == nullptr) + GError *error2 = nullptr; + char *test = g_convert(" ", 1, charset, "UTF-8", nullptr, nullptr, &error2); + if (test == nullptr) { + error.Set(convert_domain, error2->code, error2->message); + g_error_free(error2); return false; + } g_free(test); return true; } -void -SetFSCharset(const char *charset) +bool +SetFSCharset(const char *charset, Error &error) { assert(charset != nullptr); - if (!IsSupportedCharset(charset)) - FormatFatalError("invalid filesystem charset: %s", charset); + if (!CheckCharset(charset, error)) { + error.FormatPrefix("Failed to initialize filesystem charset '%s': ", + charset); + return false; + } fs_charset = charset; FormatDebug(path_domain, "SetFSCharset: fs charset is: %s", fs_charset.c_str()); + return true; } #endif -- cgit v1.2.3