diff options
Diffstat (limited to 'src/libbasic/src/fs-util.c')
-rw-r--r-- | src/libbasic/src/fs-util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libbasic/src/fs-util.c b/src/libbasic/src/fs-util.c index 03b06fd2d8..cd56843f09 100644 --- a/src/libbasic/src/fs-util.c +++ b/src/libbasic/src/fs-util.c @@ -38,6 +38,7 @@ #include "basic/mkdir.h" #include "basic/parse-util.h" #include "basic/path-util.h" +#include "basic/stat-util.h" #include "basic/stdio-util.h" #include "basic/string-util.h" #include "basic/strv.h" @@ -495,6 +496,34 @@ int get_files_in_directory(const char *path, char ***list) { return n; } +int var_tmp(char **ret) { + const char *tmp_dir = NULL; + const char *env_tmp_dir = NULL; + char *c = NULL; + int r; + + assert(ret); + + env_tmp_dir = getenv("TMPDIR"); + if (env_tmp_dir != NULL) { + r = is_dir(env_tmp_dir, true); + if (r < 0 && r != -ENOENT) + return r; + if (r > 0) + tmp_dir = env_tmp_dir; + } + + if (!tmp_dir) + tmp_dir = "/var/tmp"; + + c = strdup(tmp_dir); + if (!c) + return -ENOMEM; + *ret = c; + + return 0; +} + int inotify_add_watch_fd(int fd, int what, uint32_t mask) { char path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; int r; |