projects/linux·blob master · refs

45 lines · 958 B

1/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2/*
3 * time definitions for NOLIBC
4 * Copyright (C) 2017-2021 Willy Tarreau <[email protected]>
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
16static int _sys_clock_gettime(clockid_t clockid, struct timespec *tp);
17
18/*
19 * int gettimeofday(struct timeval *tv, struct timezone *tz);
20 */
21
22static __attribute__((unused))
23int _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
39static __attribute__((unused))
40int gettimeofday(struct timeval *tv, struct timezone *tz)
41{
42 return __sysret(_sys_gettimeofday(tv, tz));
43}
44
45#endif /* _NOLIBC_SYS_TIME_H */