From 1d1174c174fcdb1095490db595d52c8259bb26b3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 31 Oct 2025 00:47:26 +0100 Subject: [PATCH] timing: replace deprecated gettimeofday() with clock() gettimeofday() got marked obsolete in POSIX.1-2008 and removed in POSIX.1-2024. Alternatives: * clock() introduced in C89, part of POSIX.1-1995 (and meant for CPU time) * timespec_get() introduced in C11 and part of POSIX.1-2024 * clock_gettime() introduced in POSIX.1-1995, absent in ISO C so requires POSIX feature macros Signed-off-by: Haelwenn (lanodan) Monnier --- library/timing.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/library/timing.c b/library/timing.c index 1ed88639ef01..91543376f01c 100644 --- a/library/timing.c +++ b/library/timing.c @@ -38,7 +38,7 @@ struct _hr_time { #include #include struct _hr_time { - struct timeval start; + clock_t start; }; #endif /* _WIN32 && !EFIX64 && !EFI32 */ @@ -88,15 +88,11 @@ unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int r struct _hr_time *t = (struct _hr_time *) val; if (reset) { - gettimeofday(&t->start, NULL); + t->start = clock(); return 0; } else { - unsigned long delta; - struct timeval now; - gettimeofday(&now, NULL); - delta = (now.tv_sec - t->start.tv_sec) * 1000ul - + (now.tv_usec - t->start.tv_usec) / 1000; - return delta; + clock_t now = clock(); + return (now - t->start) / (CLOCKS_PER_SEC * 1000ul); } }