Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
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#ifdef __NR_gettimeofday
26 return my_syscall2(__NR_gettimeofday, tv, tz);
27#else
28 (void) tz; /* Non-NULL tz is undefined behaviour */
29
30 struct timespec tp;
31 int ret;
32
33 ret = sys_clock_gettime(CLOCK_REALTIME, &tp);
34 if (!ret && tv) {
35 tv->tv_sec = tp.tv_sec;
36 tv->tv_usec = tp.tv_nsec / 1000;
37 }
38
39 return ret;
40#endif
41}
42
43static __attribute__((unused))
44int gettimeofday(struct timeval *tv, struct timezone *tz)
45{
46 return __sysret(sys_gettimeofday(tv, tz));
47}
48
49#endif /* _NOLIBC_SYS_TIME_H */