diff options
author | Max Kellermann <max@duempel.org> | 2013-08-07 19:54:38 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-07 19:59:09 +0200 |
commit | b76a29a69ae5412c3c1d101eefa9562990e74407 (patch) | |
tree | 5c60aa1bb5e6a8d134707291d12fb4ebb77c06c8 /src/ConfigPath.cxx | |
parent | abe090ec1f2255ce422f74e5b59bffc83aaff875 (diff) | |
download | mpd-b76a29a69ae5412c3c1d101eefa9562990e74407.tar.gz mpd-b76a29a69ae5412c3c1d101eefa9562990e74407.tar.xz mpd-b76a29a69ae5412c3c1d101eefa9562990e74407.zip |
ConfigPath: return a Path object
Migrate all callers to use Path directly, instead of doing the
conversion in each caller.
Diffstat (limited to 'src/ConfigPath.cxx')
-rw-r--r-- | src/ConfigPath.cxx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/ConfigPath.cxx b/src/ConfigPath.cxx index 074891433..b90956a2a 100644 --- a/src/ConfigPath.cxx +++ b/src/ConfigPath.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "ConfigPath.hxx" +#include "fs/Path.hxx" #include "conf.h" #include <glib.h> @@ -52,17 +53,25 @@ parse_path_quark(void) return g_quark_from_static_string("path"); } -char * -parsePath(const char *path, gcc_unused GError **error_r) +Path +ParsePath(const char *path, GError **error_r) { assert(path != nullptr); assert(error_r == nullptr || *error_r == nullptr); + Path path2 = Path::FromUTF8(path); + if (path2.IsNull()) { + g_set_error(error_r, parse_path_quark(), 0, + "Failed to convert path to file system charset: %s", + path); + return Path::Null(); + } + #ifndef WIN32 if (!g_path_is_absolute(path) && path[0] != '~') { g_set_error(error_r, parse_path_quark(), 0, "not an absolute path: %s", path); - return nullptr; + return Path::Null(); } else if (path[0] == '~') { const char *home; @@ -73,7 +82,7 @@ parsePath(const char *path, gcc_unused GError **error_r) if (!passwd) { g_set_error(error_r, parse_path_quark(), 0, "no such user: %s", user); - return nullptr; + return Path::Null(); } home = passwd->pw_dir; @@ -83,7 +92,7 @@ parsePath(const char *path, gcc_unused GError **error_r) g_set_error_literal(error_r, parse_path_quark(), 0, "problems getting home " "for current user"); - return nullptr; + return Path::Null(); } } @@ -101,7 +110,7 @@ parsePath(const char *path, gcc_unused GError **error_r) g_set_error(error_r, parse_path_quark(), 0, "no such user: %s", user); g_free(user); - return nullptr; + return Path::Null(); } g_free(user); @@ -110,10 +119,10 @@ parsePath(const char *path, gcc_unused GError **error_r) path = slash; } - return g_strconcat(home, path, nullptr); + return Path::Build(home, path2); } else { #endif - return g_strdup(path); + return path2; #ifndef WIN32 } #endif |