From: Tanu Kaskinen Date: Sun, 8 Jun 2014 13:32:57 +0000 (+0300) Subject: core-util: Add pa_append_to_home_dir() X-Git-Tag: accepted/tizen/common/20140829.173154~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F26437%2F1;p=platform%2Fupstream%2Fpulseaudio.git core-util: Add pa_append_to_home_dir() Change-Id: I746d2efb5f205820480b0cbd11c23cff11367656 --- 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);