[pulseaudio-discuss] [PATCH 5/9] core-util: Add pa_append_to_home_dir()

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Sun Jun 8 06:32:57 PDT 2014


---
 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 406ce2a..c9f5b6e 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -142,14 +142,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 afd872f..cef9f88 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1653,6 +1653,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 9596b97..9495e6d 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -138,6 +138,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);
-- 
1.9.3



More information about the pulseaudio-discuss mailing list