1 /* SPDX-License-Identifier: GPL-2.0 */
8 #include "gcc-compat.h"
15 * Compute the difference of two time values.
18 * \param a Subtrahend.
19 * \param diff Result pointer.
21 * If \a diff is not \p NULL, it contains the absolute value |\a b - \a a| on
24 * \return If \a b < \a a, this function returns -1, otherwise it returns 1.
26 int tv_diff(const struct timeval
*b
, const struct timeval
*a
, struct timeval
*diff
)
30 if ((b
->tv_sec
< a
->tv_sec
) ||
31 ((b
->tv_sec
== a
->tv_sec
) && (b
->tv_usec
< a
->tv_usec
))) {
32 const struct timeval
*tmp
= a
;
39 diff
->tv_sec
= b
->tv_sec
- a
->tv_sec
;
40 if (b
->tv_usec
< a
->tv_usec
) {
42 diff
->tv_usec
= 1000 * 1000 - a
->tv_usec
+ b
->tv_usec
;
44 diff
->tv_usec
= b
->tv_usec
- a
->tv_usec
;
48 int64_t get_current_time(void)