1/*
2 * Copyright 2022, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _OBSD_COMPAT_SYS_TIME_H_
6#define _OBSD_COMPAT_SYS_TIME_H_
7
8
9#include_next <sys/time.h>
10
11
12static inline time_t
13getuptime()
14{
15	struct timeval tv;
16	getmicrouptime(&tv);
17	return tv.tv_sec;
18}
19
20
21static inline void
22USEC_TO_TIMEVAL(uint64_t us, struct timeval *tv)
23{
24	tv->tv_sec = us / 1000000;
25	tv->tv_usec = us % 1000000;
26}
27
28static inline uint64_t
29SEC_TO_NSEC(uint64_t sec)
30{
31	if (sec > UINT64_MAX / 1000000000ULL)
32		return UINT64_MAX;
33	return sec * 1000000000ULL;
34}
35
36static inline uint64_t
37MSEC_TO_NSEC(uint64_t ms)
38{
39	if (ms > UINT64_MAX / 1000000ULL)
40		return UINT64_MAX;
41	return ms * 1000000ULL;
42}
43
44
45#endif	/* _OBSD_COMPAT_SYS_TIME_H_ */
46