aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-09 22:35:15 +0200
committerMax Kellermann <max@duempel.org>2011-09-09 22:55:57 +0200
commitb42a8d236434d7ec63c742d275cd7b75adbe760b (patch)
treeee314f81f04fa7c396fd79604a61c178781a85d6
parent61fc01e79e385bc903edf1fd0cac0e5843911d58 (diff)
downloadmpd-b42a8d236434d7ec63c742d275cd7b75adbe760b.tar.gz
mpd-b42a8d236434d7ec63c742d275cd7b75adbe760b.tar.xz
mpd-b42a8d236434d7ec63c742d275cd7b75adbe760b.zip
utils: parsePath() returns GError on failure
Better error messages.
-rw-r--r--src/conf.c8
-rw-r--r--src/output/fifo_output_plugin.c6
-rw-r--r--src/utils.c27
-rw-r--r--src/utils.h3
4 files changed, 30 insertions, 14 deletions
diff --git a/src/conf.c b/src/conf.c
index b3b684aa5..245a2a811 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -513,11 +513,11 @@ config_dup_path(const char *name, GError **error_r)
if (param == NULL)
return NULL;
- char *path = parsePath(param->value);
+ char *path = parsePath(param->value, error_r);
if (G_UNLIKELY(path == NULL))
- g_set_error(error_r, config_quark(), 0,
- "Invalid path in \"%s\" at line %i",
- name, param->line);
+ g_prefix_error(error_r,
+ "Invalid path in \"%s\" at line %i: ",
+ name, param->line);
return path;
}
diff --git a/src/output/fifo_output_plugin.c b/src/output/fifo_output_plugin.c
index 8f2234dd7..e522ef6b9 100644
--- a/src/output/fifo_output_plugin.c
+++ b/src/output/fifo_output_plugin.c
@@ -190,11 +190,11 @@ fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
return NULL;
}
- path = parsePath(value);
+ path = parsePath(value, error);
g_free(value);
if (!path) {
- g_set_error(error, fifo_output_quark(), errno,
- "Could not parse \"path\" parameter");
+ g_prefix_error(error, "Invalid path in line %i: ",
+ param->line);
return NULL;
}
diff --git a/src/utils.c b/src/utils.c
index f8c08a08e..d3b21d369 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "utils.h"
+#include "glib_compat.h"
#include "conf.h"
#include <glib.h>
@@ -41,12 +42,23 @@
#include <windows.h>
#endif
+G_GNUC_CONST
+static inline GQuark
+parse_path_quark(void)
+{
+ return g_quark_from_static_string("path");
+}
+
char *
-parsePath(const char *path)
+parsePath(const char *path, G_GNUC_UNUSED GError **error_r)
{
+ assert(path != NULL);
+ assert(error_r == NULL || *error_r == NULL);
+
#ifndef WIN32
if (!g_path_is_absolute(path) && path[0] != '~') {
- g_warning("\"%s\" is not an absolute path", path);
+ g_set_error(error_r, parse_path_quark(), 0,
+ "not an absolute path: %s", path);
return NULL;
} else if (path[0] == '~') {
const char *home;
@@ -56,7 +68,8 @@ parsePath(const char *path)
if (user != NULL) {
struct passwd *passwd = getpwnam(user);
if (!passwd) {
- g_warning("no such user %s", user);
+ g_set_error(error_r, parse_path_quark(), 0,
+ "no such user: %s", user);
return NULL;
}
@@ -64,8 +77,9 @@ parsePath(const char *path)
} else {
home = g_get_home_dir();
if (home == NULL) {
- g_warning("problems getting home "
- "for current user");
+ g_set_error_literal(error_r, parse_path_quark(), 0,
+ "problems getting home "
+ "for current user");
return NULL;
}
}
@@ -81,7 +95,8 @@ parsePath(const char *path)
struct passwd *passwd = getpwnam(user);
if (!passwd) {
- g_warning("user \"%s\" not found", user);
+ g_set_error(error_r, parse_path_quark(), 0,
+ "no such user: %s", user);
g_free(user);
return NULL;
}
diff --git a/src/utils.h b/src/utils.h
index df36d1da0..f8d6657f2 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -20,6 +20,7 @@
#ifndef MPD_UTILS_H
#define MPD_UTILS_H
+#include <glib.h>
#include <stdbool.h>
#ifndef assert_static
@@ -32,6 +33,6 @@
#endif /* !assert_static */
char *
-parsePath(const char *path);
+parsePath(const char *path, GError **error_r);
#endif