diff options
author | Max Kellermann <max@duempel.org> | 2011-09-09 21:32:12 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-09 22:55:57 +0200 |
commit | 8e5f9c8160b5186c93c5d76789ffa88f3e5c2fde (patch) | |
tree | f71eb9f9c5dfa789f94eae4182490286b54788ad /src/conf.c | |
parent | c620fd42f4e8c36186c1e3c3523ac6bd1351f91d (diff) | |
download | mpd-8e5f9c8160b5186c93c5d76789ffa88f3e5c2fde.tar.gz mpd-8e5f9c8160b5186c93c5d76789ffa88f3e5c2fde.tar.xz mpd-8e5f9c8160b5186c93c5d76789ffa88f3e5c2fde.zip |
conf: turn config_get_path() into config_dup_path()
config_get_path() was somewhat flawed, because it pretended to be a
function, when it really had a side effect. The second flaw was that
it did not return the parser error, instead it aborted the whole
process, which is bad style. The new function returns a duplicated
(modified) string that must be freed by the caller, and returns a
GError on failure.
Diffstat (limited to 'src/conf.c')
-rw-r--r-- | src/conf.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/conf.c b/src/conf.c index 4434a875d..b3b684aa5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -503,22 +503,23 @@ config_get_string(const char *name, const char *default_value) return param->value; } -const char * -config_get_path(const char *name) +char * +config_dup_path(const char *name, GError **error_r) { - struct config_param *param = config_get_param(name); - char *path; + assert(error_r != NULL); + assert(*error_r == NULL); + const struct config_param *param = config_get_param(name); if (param == NULL) return NULL; - path = parsePath(param->value); - if (path == NULL) - MPD_ERROR("error parsing \"%s\" at line %i\n", - name, param->line); + char *path = parsePath(param->value); + if (G_UNLIKELY(path == NULL)) + g_set_error(error_r, config_quark(), 0, + "Invalid path in \"%s\" at line %i", + name, param->line); - g_free(param->value); - return param->value = path; + return path; } unsigned |