summaryrefslogtreecommitdiff
path: root/util/nvmutil/include/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/nvmutil/include/common.h')
-rw-r--r--util/nvmutil/include/common.h44
1 files changed, 37 insertions, 7 deletions
diff --git a/util/nvmutil/include/common.h b/util/nvmutil/include/common.h
index 4173ca6e..46fbcb38 100644
--- a/util/nvmutil/include/common.h
+++ b/util/nvmutil/include/common.h
@@ -1,6 +1,4 @@
-/*
- * SPDX-License-Identifier: MIT
- *
+/* SPDX-License-Identifier: MIT
* Copyright (c) 2022-2026 Leah Rowe <leah@libreboot.org>
*/
@@ -11,6 +9,25 @@
#include <sys/stat.h>
#include <limits.h>
+/* for linux getrandom
+ */
+#if defined(__linux__)
+#include <errno.h>
+#if defined(__has_include)
+#if __has_include(<sys/random.h>)
+#include <sys/random.h>
+#define HAVE_GETRANDOM 1
+#endif
+#endif
+#if !defined(HAVE_GETRANDOM)
+#include <sys/syscall.h>
+#if defined(SYS_getrandom)
+#define HAVE_GETRANDOM_SYSCALL 1
+#endif
+#endif
+
+#endif
+
#define items(x) (sizeof((x)) / sizeof((x)[0]))
/* system prototypes
@@ -35,7 +52,7 @@ int fchmod(int fd, mode_t mode);
#define MAX_CMD_LEN 50
#ifndef PATH_LEN
-#define PATH_LEN 1024
+#define PATH_LEN 4096
#endif
#define OFF_ERR 0
@@ -320,6 +337,18 @@ void set_mac_nib(unsigned long mac_str_pos,
unsigned long mac_byte_pos, unsigned long mac_nib_pos);
unsigned short hextonum(char ch_s);
unsigned long rlong(void);
+#if !(defined(FALLBACK_RAND_1989) && \
+ ((FALLBACK_RAND_1989) > 0))
+#if defined(__linux__)
+#if defined(HAVE_GETRANDOM) || \
+ defined(HAVE_GETRANDOM_SYSCALL)
+int fallback_rand_getrandom(void *buf, size_t len);
+#endif
+#endif
+#else
+unsigned long fallback_rand_1989(void);
+unsigned long entropy_jitter(void);
+#endif
void write_mac_part(unsigned long partnum);
/* Helper functions for command: dump
@@ -421,8 +450,8 @@ const char *getnvmprogname(void);
*/
char *new_tmpfile(int *fd, int local, const char *path);
-int x_i_mkstemp(char *template);
-char *x_c_tmpdir(void);
+int mkstemp_n(char *template);
+char *get_tmpdir(void);
int close_on_eintr(int fd);
int fsync_on_eintr(int fd);
@@ -440,6 +469,8 @@ typedef char static_assert_unsigned_int_is_4[
(sizeof(unsigned int) >= 4) ? 1 : -1];
typedef char static_assert_unsigned_long_is_4[
(sizeof(unsigned long) >= 4) ? 1 : -1];
+typedef char static_assert_long_ulong[
+ (sizeof(unsigned long) == sizeof(long)) ? 1 : -1];
typedef char static_assert_int_ge_32[(sizeof(int) >= 4) ? 1 : -1];
typedef char static_assert_twos_complement[
((-1 & 3) == 3) ? 1 : -1
@@ -487,6 +518,5 @@ typedef char bool_no_loop_eagain[(NO_LOOP_EAGAIN==0)?1:-1];
typedef char bool_off_err[(OFF_ERR==0)?1:-1];
typedef char bool_off_reset[(OFF_RESET==0||OFF_RESET==1)?1:-1];
-
#endif
#endif