mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
util/nvmutil: more reliable TMPDIR handling
more portable Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+20
-1
@@ -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 ".";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user