diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:10:25 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:10:25 +0000 |
| commit | e5e107d8cd51efa26387f10de85a2549083ad89d (patch) | |
| tree | 7374254f255136b7628e98da6a4111dda25d7708 | |
| parent | bdb43afac6edef21a15f99b8c3beac01be8b86f7 (diff) | |
util/nvmutil: more reliable TMPDIR handling
more portable
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 359fdc70..13919804 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -477,6 +477,7 @@ static char *new_tmpfile(int *fd, int local, const char *path); static int x_i_mkstemp(char *template); static char *x_c_strrchr(const char *s, int c); static int x_i_rename(const char *src, const char *dst); +static char *x_c_tmpdir(void); /* * Sizes in bytes: @@ -2889,7 +2890,7 @@ new_tmpfile(int *fd, int local, const char *path) */ tmpdir_len = sizeof(default_tmpname); } else { - base = getenv("TMPDIR"); + base = x_c_tmpdir(); if (base == NULL) base = tmp_default; @@ -3075,3 +3076,21 @@ x_i_rename(const char *src, const char *dst) return 0; } + +static char * +x_c_tmpdir(void) +{ + char *t; + + t = getenv("TMPDIR"); + if (t && *t) + return t; + + if (access("/tmp", W_OK) == 0) + return "/tmp"; + + if (access("/var/tmp", W_OK) == 0) + return "/var/tmp"; + + return "."; +} |
