aboutsummaryrefslogtreecommitdiffstats
path: root/src/ConfigPath.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-09-12 10:10:05 +0200
committerMax Kellermann <max@duempel.org>2013-09-12 10:35:40 +0200
commit3aaf013dd126321b2bca6d4cda26c50fff0a342f (patch)
tree07a7ac2733454c65388beb1a9485078306847748 /src/ConfigPath.cxx
parent5f2705ab0755c9e1bb583223cf6ef27474813337 (diff)
downloadmpd-3aaf013dd126321b2bca6d4cda26c50fff0a342f.tar.gz
mpd-3aaf013dd126321b2bca6d4cda26c50fff0a342f.tar.xz
mpd-3aaf013dd126321b2bca6d4cda26c50fff0a342f.zip
ConfigPath: convert "home" variable to Path object
Use Path::FromUTF8() for the g_get_home_dir() return value instead of assuming it's already FS charset.
Diffstat (limited to '')
-rw-r--r--src/ConfigPath.cxx20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/ConfigPath.cxx b/src/ConfigPath.cxx
index 1c6875bd4..9fd3876bf 100644
--- a/src/ConfigPath.cxx
+++ b/src/ConfigPath.cxx
@@ -34,37 +34,39 @@
/**
* Determine a given user's home directory.
*/
-static const char *
+static Path
GetHome(const char *user, Error &error)
{
passwd *pw = getpwnam(user);
if (pw == nullptr) {
error.Format(path_domain,
"no such user: %s", user);
- return nullptr;
+ return Path::Null();
}
- return pw->pw_dir;
+ return Path::FromFS(pw->pw_dir);
}
/**
* Determine the current user's home directory.
*/
-static const char *
+static Path
GetHome(Error &error)
{
const char *home = g_get_home_dir();
- if (home == nullptr)
+ if (home == nullptr) {
error.Set(path_domain,
"problems getting home for current user");
+ return Path::Null();
+ }
- return home;
+ return Path::FromUTF8(home, error);
}
/**
* Determine the configured user's home directory.
*/
-static const char *
+static Path
GetConfiguredHome(Error &error)
{
const char *user = config_get_string(CONF_USER, nullptr);
@@ -90,7 +92,7 @@ ParsePath(const char *path, Error &error)
"not an absolute path: %s", path);
return Path::Null();
} else if (path[0] == '~') {
- const char *home;
+ Path home = Path::Null();
if (path[1] == '/' || path[1] == '\0') {
home = GetConfiguredHome(error);
@@ -110,7 +112,7 @@ ParsePath(const char *path, Error &error)
path = slash;
}
- if (home == nullptr)
+ if (home.IsNull())
return Path::Null();
return Path::Build(home, path2);