zephyr/lib/libc/common/source/time/time.c
Kumar Gala 672aeace88 libc: share time() between minimal libc and armclang libc
Introduce a place to share implementations of libc functions that
are needed by different libc versions.  Place time() in this common
location so it can be shared when building for either minimal libc or
armclang libc.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-27 09:49:40 +02:00

28 lines
419 B
C

/*
* Copyright (c) 2021 Golioth, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <time.h>
/* clock_gettime() prototype */
#include <zephyr/posix/time.h>
time_t time(time_t *tloc)
{
struct timespec ts;
int ret;
ret = clock_gettime(CLOCK_REALTIME, &ts);
if (ret < 0) {
/* errno is already set by clock_gettime */
return (time_t) -1;
}
if (tloc) {
*tloc = ts.tv_sec;
}
return ts.tv_sec;
}