From 139f19f867bec728466af6b29f9a96178b96992b Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 16 Mar 2026 15:21:59 +0000 Subject: util/nvmutil: portable gettimeofday Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 12a6cf5a..8de30619 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -373,6 +373,7 @@ static ushort hextonum(char ch_s); static ushort rhex(void); static ushort read_urandom(void); static ulong entropy_jitter(void); +static int x_i_gettimeofday(struct timeval *tv, void *tz); static void write_mac_part(size_t partnum); /* @@ -1356,7 +1357,7 @@ rhex(void) /* Fallback */ - gettimeofday(&tv, NULL); + x_i_gettimeofday(&tv, NULL); mix = (ulong)tv.tv_sec ^ (ulong)tv.tv_usec @@ -1421,9 +1422,9 @@ entropy_jitter(void) int i; for (i = 0; i < 8; i++) { - gettimeofday(&a, NULL); + x_i_gettimeofday(&a, NULL); getpid(); - gettimeofday(&b, NULL); + x_i_gettimeofday(&b, NULL); /* * prevent negative numbers to prevent overflow, @@ -1440,6 +1441,21 @@ entropy_jitter(void) return mix; } +static int +x_i_gettimeofday(struct timeval *tv, void *tz) +{ + time_t t; + + (void)tz; + + t = time(NULL); + + tv->tv_sec = t; + tv->tv_usec = (long)clock() % 1000000; + + return 0; +} + static void write_mac_part(size_t partnum) { -- cgit v1.2.1