Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: minimal: implement time() API #33397

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/libc/minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ zephyr_library_sources(
source/stdout/fprintf.c
source/time/gmtime.c
)

zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK source/time/time.c)
2 changes: 2 additions & 0 deletions lib/libc/minimal/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *_MLIBC_RESTRICT timep,
struct tm *_MLIBC_RESTRICT result);

time_t time(time_t *tloc);

#ifdef __cplusplus
}
#endif
Expand Down
28 changes: 28 additions & 0 deletions lib/libc/minimal/source/time/time.c
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 0 additions & 5 deletions samples/net/civetweb/common/src/libc_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ long long strtoll(const char *str, char **endptr, int 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,
* but they are available only if CONFIG_NET_SOCKETS_POSIX_NAMES is enabled
Expand Down