summaryrefslogtreecommitdiff
path: root/src/pulsecore
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-09-17 21:06:54 +0200
committerLennart Poettering <lennart@poettering.net>2009-09-17 21:06:54 +0200
commit7b76ea378460bf3e037dff90742f88f74ee70b11 (patch)
treee697a297de5f3f4ad379fa8483b83946da142ee2 /src/pulsecore
parent2d9168ceb388cbb6dba49cc3a531921f78ec3295 (diff)
core-util: unify how we determine the temporary directory
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/core-util.c33
-rw-r--r--src/pulsecore/core-util.h2
2 files changed, 25 insertions, 10 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 690f34c9..8e98e857 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -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";
+}
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index ccc9a38e..84752d4d 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -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