libc: minimal: implement time() API
Implement time() API by using clock_gettime(CLOCK_REALTIME, ...). Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
parent
524853ecfa
commit
064c6ef830
4 changed files with 32 additions and 5 deletions
|
@ -20,3 +20,5 @@ zephyr_library_sources(
|
||||||
source/stdout/fprintf.c
|
source/stdout/fprintf.c
|
||||||
source/time/gmtime.c
|
source/time/gmtime.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK source/time/time.c)
|
||||||
|
|
|
@ -52,6 +52,8 @@ struct tm *gmtime(const time_t *timep);
|
||||||
struct tm *gmtime_r(const time_t *_MLIBC_RESTRICT timep,
|
struct tm *gmtime_r(const time_t *_MLIBC_RESTRICT timep,
|
||||||
struct tm *_MLIBC_RESTRICT result);
|
struct tm *_MLIBC_RESTRICT result);
|
||||||
|
|
||||||
|
time_t time(time_t *tloc);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
28
lib/libc/minimal/source/time/time.c
Normal file
28
lib/libc/minimal/source/time/time.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Golioth, Inc.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/* clock_gettime() prototype */
|
||||||
|
#include <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;
|
||||||
|
}
|
|
@ -159,11 +159,6 @@ long long strtoll(const char *str, char **endptr, int base)
|
||||||
return (long long)strtol(str, endptr, base);
|
return (long long)strtol(str, endptr, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t time(time_t *t)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Most of the wrappers below are copies of the wrappers in net/sockets.h,
|
* Most of the wrappers below are copies of the wrappers in net/sockets.h,
|
||||||
* but they are available only if CONFIG_NET_SOCKETS_POSIX_NAMES is enabled
|
* but they are available only if CONFIG_NET_SOCKETS_POSIX_NAMES is enabled
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue