]> code.delx.au - pulseaudio/commitdiff
add new pa_get_state_dir() function, move pa_strnull() here
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Apr 2008 16:58:07 +0000 (16:58 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Apr 2008 16:58:07 +0000 (16:58 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2257 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulsecore/core-util.c
src/pulsecore/core-util.h

index 61d04c2d730e4a3d7933d551ac04630106f7cfe1..28885b2ce0905e90a71da066dccd8e3f6acf727f 100644 (file)
@@ -1093,6 +1093,35 @@ int pa_unlock_lockfile(const char *fn, int fd) {
     return r;
 }
 
+char *pa_get_state_dir(void) {
+    const char *e;
+    char *d;
+
+    if ((e = getenv("PULSE_STATE_PATH")))
+        d = pa_xstrdup(e);
+    else {
+        char h[PATH_MAX];
+
+        if (!pa_get_home_dir(h, sizeof(h))) {
+            pa_log_error("Failed to get home directory.");
+            return NULL;
+        }
+
+        d = pa_sprintf_malloc("%s/.pulse", h);
+    }
+
+    mkdir(d, 0755);
+
+    if (access(d, W_OK) == 0)
+        return d;
+
+    pa_log_error("Failed to set up state directory %s", d);
+
+    pa_xfree(d);
+
+    return NULL;
+}
+
 /* Try to open a configuration file. If "env" is specified, open the
  * value of the specified environment variable. Otherwise look for a
  * file "local" in the home directory or a file "global" in global
index c8760a1fdb39e1c949e2f06b1b048b01c7279ca2..d5c0a3f6dfba70734dec80533268e05fde98b936 100644 (file)
@@ -30,7 +30,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
 #include <pulsecore/macro.h>
 
 struct timeval;
@@ -67,6 +67,10 @@ static inline const char *pa_yes_no(pa_bool_t b) {
     return b ? "yes" : "no";
 }
 
+static inline const char *pa_strnull(const char *x) {
+    return x ? x : "(null)";
+}
+
 char *pa_split(const char *c, const char*delimiters, const char **state);
 char *pa_split_spaces(const char *c, const char **state);
 
@@ -129,4 +133,6 @@ void pa_close_pipe(int fds[2]);
 
 char *pa_readlink(const char *p);
 
+char *pa_get_state_dir(void);
+
 #endif