Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/include/nolibc/sys/time.h
26292 views
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
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
#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
43
static __attribute__((unused))
44
int gettimeofday(struct timeval *tv, struct timezone *tz)
45
{
46
return __sysret(sys_gettimeofday(tv, tz));
47
}
48
49
#endif /* _NOLIBC_SYS_TIME_H */
50
51