xref: /linux/tools/include/nolibc/sys/time.h (revision 015a99fa76650e7d6efa3e36f20c0f5b346fe9ce)
1face777aSThomas Weißschuh /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2face777aSThomas Weißschuh /*
3face777aSThomas Weißschuh  * time definitions for NOLIBC
4face777aSThomas Weißschuh  * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
5face777aSThomas Weißschuh  */
6face777aSThomas Weißschuh 
73785289fSThomas Weißschuh /* make sure to include all global symbols */
83785289fSThomas Weißschuh #include "../nolibc.h"
93785289fSThomas Weißschuh 
10face777aSThomas Weißschuh #ifndef _NOLIBC_SYS_TIME_H
11face777aSThomas Weißschuh #define _NOLIBC_SYS_TIME_H
12face777aSThomas Weißschuh 
13face777aSThomas Weißschuh #include "../arch.h"
14face777aSThomas Weißschuh #include "../sys.h"
15face777aSThomas Weißschuh 
16*5e7392dcSThomas Weißschuh static int sys_clock_gettime(clockid_t clockid, struct timespec *tp);
17*5e7392dcSThomas Weißschuh 
18face777aSThomas Weißschuh /*
19face777aSThomas Weißschuh  * int gettimeofday(struct timeval *tv, struct timezone *tz);
20face777aSThomas Weißschuh  */
21face777aSThomas Weißschuh 
22face777aSThomas Weißschuh static __attribute__((unused))
sys_gettimeofday(struct timeval * tv,struct timezone * tz)23face777aSThomas Weißschuh int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
24face777aSThomas Weißschuh {
25face777aSThomas Weißschuh #ifdef __NR_gettimeofday
26face777aSThomas Weißschuh 	return my_syscall2(__NR_gettimeofday, tv, tz);
27face777aSThomas Weißschuh #else
28*5e7392dcSThomas Weißschuh 	(void) tz; /* Non-NULL tz is undefined behaviour */
29*5e7392dcSThomas Weißschuh 
30*5e7392dcSThomas Weißschuh 	struct timespec tp;
31*5e7392dcSThomas Weißschuh 	int ret;
32*5e7392dcSThomas Weißschuh 
33*5e7392dcSThomas Weißschuh 	ret = sys_clock_gettime(CLOCK_REALTIME, &tp);
34*5e7392dcSThomas Weißschuh 	if (!ret && tv) {
35*5e7392dcSThomas Weißschuh 		tv->tv_sec = tp.tv_sec;
36*5e7392dcSThomas Weißschuh 		tv->tv_usec = tp.tv_nsec / 1000;
37*5e7392dcSThomas Weißschuh 	}
38*5e7392dcSThomas Weißschuh 
39*5e7392dcSThomas Weißschuh 	return ret;
40face777aSThomas Weißschuh #endif
41face777aSThomas Weißschuh }
42face777aSThomas Weißschuh 
43face777aSThomas Weißschuh static __attribute__((unused))
gettimeofday(struct timeval * tv,struct timezone * tz)44face777aSThomas Weißschuh int gettimeofday(struct timeval *tv, struct timezone *tz)
45face777aSThomas Weißschuh {
46face777aSThomas Weißschuh 	return __sysret(sys_gettimeofday(tv, tz));
47face777aSThomas Weißschuh }
48face777aSThomas Weißschuh 
49face777aSThomas Weißschuh #endif /* _NOLIBC_SYS_TIME_H */
50