diff options
author | Max Kellermann <max@duempel.org> | 2013-09-12 10:02:11 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-09-12 10:17:41 +0200 |
commit | 1ee6a78cb727561e75a5d60135bb0cd7956f70b0 (patch) | |
tree | 1b04fc472927341f818d3d571456fb495dd43ece /src | |
parent | bf4ee48efad262c650b6b1a5b61ebe837d59f910 (diff) | |
download | mpd-1ee6a78cb727561e75a5d60135bb0cd7956f70b0.tar.gz mpd-1ee6a78cb727561e75a5d60135bb0cd7956f70b0.tar.xz mpd-1ee6a78cb727561e75a5d60135bb0cd7956f70b0.zip |
Path: add FromUTF8() overload that returns an Error
Diffstat (limited to '')
-rw-r--r-- | src/ConfigPath.cxx | 8 | ||||
-rw-r--r-- | src/Main.cxx | 8 | ||||
-rw-r--r-- | src/fs/Path.cxx | 13 | ||||
-rw-r--r-- | src/fs/Path.hxx | 5 |
4 files changed, 26 insertions, 8 deletions
diff --git a/src/ConfigPath.cxx b/src/ConfigPath.cxx index 86f70dfd3..f9236df2a 100644 --- a/src/ConfigPath.cxx +++ b/src/ConfigPath.cxx @@ -53,13 +53,9 @@ ParsePath(const char *path, Error &error) { assert(path != nullptr); - Path path2 = Path::FromUTF8(path); - if (path2.IsNull()) { - error.Format(path_domain, - "Failed to convert path to file system charset: %s", - path); + Path path2 = Path::FromUTF8(path, error); + if (path2.IsNull()) return Path::Null(); - } #ifndef WIN32 if (!g_path_is_absolute(path) && path[0] != '~') { diff --git a/src/Main.cxx b/src/Main.cxx index a1138a908..80c6b0069 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -138,8 +138,12 @@ glue_mapper_init(Error &error) if (playlist_dir.IsNull() && error.IsDefined()) return false; - if (music_dir.IsNull()) - music_dir = Path::FromUTF8(g_get_user_special_dir(G_USER_DIRECTORY_MUSIC)); + if (music_dir.IsNull()) { + music_dir = Path::FromUTF8(g_get_user_special_dir(G_USER_DIRECTORY_MUSIC), + error); + if (music_dir.IsNull()) + return false; + } mapper_init(std::move(music_dir), std::move(playlist_dir)); return true; diff --git a/src/fs/Path.cxx b/src/fs/Path.cxx index c063025c8..f04823661 100644 --- a/src/fs/Path.cxx +++ b/src/fs/Path.cxx @@ -21,6 +21,7 @@ #include "fs/Path.hxx" #include "ConfigGlobal.hxx" #include "system/FatalError.hxx" +#include "util/Error.hxx" #include "util/Domain.hxx" #include "gcc.h" @@ -89,6 +90,18 @@ Path Path::FromUTF8(const char *path_utf8) return Path(Donate(), p); } +Path +Path::FromUTF8(const char *path_utf8, Error &error) +{ + Path path = FromUTF8(path_utf8); + if (path.IsNull()) + error.Format(path_domain, + "Failed to convert to file system charset: %s", + path_utf8); + + return path; +} + gcc_pure static bool IsSupportedCharset(const char *charset) diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx index dd4cf38a7..8bfc9b8c4 100644 --- a/src/fs/Path.hxx +++ b/src/fs/Path.hxx @@ -44,6 +44,8 @@ # endif #endif +class Error; + extern const class Domain path_domain; /** @@ -151,6 +153,9 @@ public: gcc_pure static Path FromUTF8(const char *path_utf8); + gcc_pure + static Path FromUTF8(const char *path_utf8, Error &error); + /** * Convert the path to UTF-8. * Returns empty string on error or if #path_fs is null pointer. |