diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:35:06 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:36:07 +0000 |
| commit | 7674550083613afae768e15b22be86b4a91dd43d (patch) | |
| tree | 1b57844e3ab8c10b1d806a4e8178f36a5315a5b2 /util | |
| parent | 1cc7c91b2cb0b49b97154c72fff68e4e5905a44e (diff) | |
util/nvmutil: don't use mktemp
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index a0304ee4..5058f15b 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -304,6 +304,10 @@ typedef char static_assert_off_t_is_32[(sizeof(off_t) >= 4) ? 1 : -1]; #define O_BINARY 0 #endif +#ifndef O_EXCL +#define O_EXCL 0 +#endif + #ifndef O_NONBLOCK #define O_NONBLOCK 0 #endif @@ -3001,15 +3005,32 @@ static int x_i_mkstemp(char *template) { int fd; - int i; + int i, j; + unsigned long len; + char *p; - for (i = 0; i < 10; i++) { - if (mktemp(template) == NULL) - return -1; + char ch[] = "abcdefghijklmnopqrstuvwxyz0123456789"; + + len = xstrxlen(template, PATH_LEN); + + /* find trailing XXXXXX */ + if (len < 6) + return -1; + + p = template + len - 6; + + for (i = 0; i < 100; i++) { + + for (j = 0; j < 6; j++) + p[j] = ch[rhex() & 31]; fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600); + if (fd >= 0) return fd; + + if (errno != EEXIST) + return -1; } errno = EEXIST; |
