From: Kiran Rangoon Date: Mon, 29 Dec 2025 03:50:58 +0000 (-0500) Subject: libuuid: refactor gregorian_to_unix to populate timeval directly X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49dcd5e635ffeaf8417a06337c31ccdd0ac68ae2;p=thirdparty%2Futil-linux.git libuuid: refactor gregorian_to_unix to populate timeval directly 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 --- 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)