From 17964083d3a5ea7a853deea3e48b154da87cbf3c Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 17 May 2025 21:30:27 -0400 Subject: [PATCH] libc: common: time: use sys_clock api rather than posix Remove POSIX clock_gettime() from the common libc time implementation, since POSIX should not be a dependency for ISO C. Instead, use the newly added lib/os sys_clock API. Specifically, sys_clock_gettime(). Signed-off-by: Chris Friedt --- lib/libc/common/source/time/time.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/libc/common/source/time/time.c b/lib/libc/common/source/time/time.c index 85840fa8cd9..5eccd733d97 100644 --- a/lib/libc/common/source/time/time.c +++ b/lib/libc/common/source/time/time.c @@ -1,22 +1,23 @@ /* * Copyright (c) 2021 Golioth, Inc. + * Copyright (c) 2025 Tenstorrent AI ULC * * SPDX-License-Identifier: Apache-2.0 */ +#include #include -/* clock_gettime() prototype */ -#include +#include time_t time(time_t *tloc) { struct timespec ts; int ret; - ret = clock_gettime(CLOCK_REALTIME, &ts); + ret = sys_clock_gettime(SYS_CLOCK_REALTIME, &ts); if (ret < 0) { - /* errno is already set by clock_gettime */ + errno = -ret; return (time_t) -1; }