From 6aafa43d4b318806ddf886fa92a139897cbc3335 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Sun, 8 Jun 2014 16:32:57 +0300 Subject: [PATCH] core-util: Add pa_append_to_home_dir() Change-Id: I746d2efb5f205820480b0cbd11c23cff11367656 --- src/pulsecore/authkey.c | 7 ++----- src/pulsecore/core-util.c | 17 +++++++++++++++++ src/pulsecore/core-util.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c index 03c0c4b..be31e98 100644 --- a/src/pulsecore/authkey.c +++ b/src/pulsecore/authkey.c @@ -156,14 +156,11 @@ static char *normalize_path(const char *fn) { #else if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') { #endif - char *homedir, *s; + char *s; - if (!(homedir = pa_get_home_dir_malloc())) + if (pa_append_to_home_dir(fn, &s) < 0) return NULL; - s = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", homedir, fn); - pa_xfree(homedir); - return s; } diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 508b3d3..99aa51f 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1685,6 +1685,23 @@ char *pa_get_home_dir_malloc(void) { return homedir; } +int pa_append_to_home_dir(const char *path, char **_r) { + char *home_dir; + + pa_assert(path); + pa_assert(_r); + + home_dir = pa_get_home_dir_malloc(); + if (!home_dir) { + pa_log("Failed to get home directory."); + return -PA_ERR_NOENTITY; + } + + *_r = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", home_dir, path); + pa_xfree(home_dir); + return 0; +} + char *pa_get_binary_name_malloc(void) { char *t; size_t allocated = 128; diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index aba1863..05d628e 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -137,6 +137,7 @@ char* pa_find_config_file(const char *global, const char *local, const char *env char *pa_get_runtime_dir(void); char *pa_get_state_dir(void); char *pa_get_home_dir_malloc(void); +int pa_append_to_home_dir(const char *path, char **_r); char *pa_get_binary_name_malloc(void); char *pa_runtime_path(const char *fn); char *pa_state_path(const char *fn, bool prepend_machine_id); -- 2.7.4