From 49dcd5e635ffeaf8417a06337c31ccdd0ac68ae2 Mon Sep 17 00:00:00 2001 From: Kiran Rangoon Date: Sun, 28 Dec 2025 22:50:58 -0500 Subject: [PATCH] libuuid: refactor gregorian_to_unix to populate timeval directly MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change function signature to take struct timeval pointer and populate it directly, eliminating duplicate conversion code in callers. Signed-off-by: Kiran Rangoon Reviewed-by: Thomas Weißschuh --- libuuid/src/uuid_time.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libuuid/src/uuid_time.c b/libuuid/src/uuid_time.c index e2b991d74..2f7c6652c 100644 --- a/libuuid/src/uuid_time.c +++ b/libuuid/src/uuid_time.c @@ -60,10 +60,12 @@ /* prototype to make compiler happy */ time_t __uuid_time(const uuid_t uu, struct timeval *ret_tv); -static uint64_t gregorian_to_unix(uint64_t ts) +static void gregorian_to_unix(uint64_t ts, struct timeval *tv) { const uint64_t offset = 0x01B21DD213814000ULL; - return ts - offset; + uint64_t clock_reg = ts - offset; + tv->tv_sec = clock_reg / 10000000; + tv->tv_usec = (clock_reg % 10000000) / 10; } static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv) @@ -74,9 +76,7 @@ static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv) high = uuid->time_mid | ((uuid->time_hi_and_version & 0xFFF) << 16); clock_reg = uuid->time_low | ((uint64_t) high << 32); - clock_reg = gregorian_to_unix(clock_reg); - tv->tv_sec = clock_reg / 10000000; - tv->tv_usec = (clock_reg % 10000000) / 10; + gregorian_to_unix(clock_reg, tv); } static void uuid_time_v6(const struct uuid *uuid, struct timeval *tv) @@ -89,9 +89,7 @@ static void uuid_time_v6(const struct uuid *uuid, struct timeval *tv) clock_reg <<= 12; clock_reg |= uuid->time_hi_and_version & 0xFFF; - clock_reg = gregorian_to_unix(clock_reg); - tv->tv_sec = clock_reg / 10000000; - tv->tv_usec = (clock_reg % 10000000) / 10; + gregorian_to_unix(clock_reg, tv); } static void uuid_time_v7(const struct uuid *uuid, struct timeval *tv) -- 2.47.3