]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: refactor gregorian_to_unix to populate timeval directly
authorKiran Rangoon <kiranrangoon0@gmail.com>
Mon, 29 Dec 2025 03:50:58 +0000 (22:50 -0500)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 29 Dec 2025 13:43:31 +0000 (14:43 +0100)
Change function signature to take struct timeval pointer and populate
it directly, eliminating duplicate conversion code in callers.

Signed-off-by: Kiran Rangoon <kiranrangoon0@gmail.com>
Reviewed-by: Thomas Weißschuh <thomas@t-8ch.de>
libuuid/src/uuid_time.c

index e2b991d745731b1ee0ab918030d97fd228fb6ca1..2f7c6652c8904e8510cc2389c9ed51b28d41702d 100644 (file)
 /* 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)