mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
core-util: unify how we determine the temporary directory
This commit is contained in:
parent
2d9168ceb3
commit
7b76ea3784
3 changed files with 26 additions and 20 deletions
|
|
@ -1378,19 +1378,10 @@ static char* make_random_dir(mode_t m) {
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"0123456789";
|
"0123456789";
|
||||||
|
|
||||||
const char *tmpdir;
|
|
||||||
char *fn;
|
char *fn;
|
||||||
size_t pathlen;
|
size_t pathlen;
|
||||||
|
|
||||||
if (!(tmpdir = getenv("TMPDIR")))
|
fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", pa_get_temp_dir());
|
||||||
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);
|
|
||||||
pathlen = strlen(fn);
|
pathlen = strlen(fn);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
@ -2854,3 +2845,25 @@ pa_bool_t pa_run_from_build_tree(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,4 +249,6 @@ void pa_reset_personality(void);
|
||||||
pa_bool_t pa_run_from_build_tree(void);
|
pa_bool_t pa_run_from_build_tree(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char *pa_get_temp_dir(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1398,17 +1398,8 @@ static int sndstat_open(int flags, int *_errno) {
|
||||||
mode_t u;
|
mode_t u;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int e;
|
int e;
|
||||||
const char *tmpdir;
|
|
||||||
|
|
||||||
if (!(tmpdir = getenv("TMPDIR")))
|
fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", pa_get_temp_dir());
|
||||||
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);
|
|
||||||
|
|
||||||
debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n");
|
debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue