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