1 /*
2  * Copyright (c) 2021 Golioth, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <time.h>
8 
9 /* clock_gettime() prototype */
10 #include <zephyr/posix/time.h>
11 
time(time_t * tloc)12 time_t time(time_t *tloc)
13 {
14 	struct timespec ts;
15 	int ret;
16 
17 	ret = clock_gettime(CLOCK_REALTIME, &ts);
18 	if (ret < 0) {
19 		/* errno is already set by clock_gettime */
20 		return (time_t) -1;
21 	}
22 
23 	if (tloc) {
24 		*tloc = ts.tv_sec;
25 	}
26 
27 	return ts.tv_sec;
28 }
29