Browse Source

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 <cfriedt@tenstorrent.com>
pull/91872/head
Chris Friedt 2 months ago committed by Benjamin Cabé
parent
commit
17964083d3
  1. 9
      lib/libc/common/source/time/time.c

9
lib/libc/common/source/time/time.c

@ -1,22 +1,23 @@ @@ -1,22 +1,23 @@
/*
* Copyright (c) 2021 Golioth, Inc.
* Copyright (c) 2025 Tenstorrent AI ULC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <errno.h>
#include <time.h>
/* clock_gettime() prototype */
#include <zephyr/posix/time.h>
#include <zephyr/sys/clock.h>
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;
}

Loading…
Cancel
Save