]> code.delx.au - pulseaudio/commitdiff
core-util: unify how we determine the temporary directory
authorLennart Poettering <lennart@poettering.net>
Thu, 17 Sep 2009 19:06:54 +0000 (21:06 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 17 Sep 2009 19:06:54 +0000 (21:06 +0200)
src/pulsecore/core-util.c
src/pulsecore/core-util.h
src/utils/padsp.c

index 690f34c9fa2bdf354a09b0f1cc9f4c3b082b145d..8e98e8579c490b7a994d0b0a63d498504a37fdb4 100644 (file)
@@ -1378,19 +1378,10 @@ static char* make_random_dir(mode_t m) {
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         "0123456789";
 
-    const char *tmpdir;
     char *fn;
     size_t pathlen;
 
-    if (!(tmpdir = getenv("TMPDIR")))
-        if (!(tmpdir = getenv("TMP")))
-            if (!(tmpdir = getenv("TEMP")))
-                tmpdir = getenv("TEMPDIR");
-
-    if (!tmpdir || !pa_is_path_absolute(tmpdir))
-        tmpdir = "/tmp";
-
-    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", tmpdir);
+    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", pa_get_temp_dir());
     pathlen = strlen(fn);
 
     for (;;) {
@@ -2854,3 +2845,25 @@ pa_bool_t pa_run_from_build_tree(void) {
 }
 
 #endif
+
+const char *pa_get_temp_dir(void) {
+    const char *t;
+
+    if ((t = getenv("TMPDIR")) &&
+        pa_is_path_absolute(t))
+        return t;
+
+    if ((t = getenv("TMP")) &&
+        pa_is_path_absolute(t))
+        return t;
+
+    if ((t = getenv("TEMP")) &&
+        pa_is_path_absolute(t))
+        return t;
+
+    if ((t = getenv("TEMPDIR")) &&
+        pa_is_path_absolute(t))
+        return t;
+
+    return "/tmp";
+}
index ccc9a38eee6dddfb3c8a1d8e59cdf7b345145f58..84752d4d813836d89e516950b2dbe829a470805c 100644 (file)
@@ -249,4 +249,6 @@ void pa_reset_personality(void);
 pa_bool_t pa_run_from_build_tree(void);
 #endif
 
+const char *pa_get_temp_dir(void);
+
 #endif
index c8c0874da66b81250ade7e24b02cac5dd3cd44be..2ed0a0397b0c51ffd806b5285c6703255a8cae4d 100644 (file)
@@ -1398,17 +1398,8 @@ static int sndstat_open(int flags, int *_errno) {
     mode_t u;
     int fd = -1;
     int e;
-    const char *tmpdir;
 
-    if (!(tmpdir = getenv("TMPDIR")))
-        if (!(tmpdir = getenv("TMP")))
-            if (!(tmpdir = getenv("TEMP")))
-                tmpdir = getenv("TEMPDIR");
-
-    if (!tmpdir || !pa_is_path_absolute(tmpdir))
-        tmpdir = "/tmp";
-
-    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", tmpdir);
+    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", pa_get_temp_dir());
 
     debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n");