/* SPDX-License-Identifier: GPL-2.0 */ #include #include #include #include #include #include "gcc-compat.h" #include "err.h" #include "str.h" #include "log.h" #include "time.h" /* * Compute the difference of two time values. If b < a the function returns * -1, otherwise it returns 1. If diff is not NULL, |b - a| is returned through * this pointer. */ int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff) { int ret = 1; if ((b->tv_sec < a->tv_sec) || ((b->tv_sec == a->tv_sec) && (b->tv_usec < a->tv_usec))) { const struct timeval *tmp = a; a = b; b = tmp; ret = -1; } if (!diff) return ret; diff->tv_sec = b->tv_sec - a->tv_sec; if (b->tv_usec < a->tv_usec) { diff->tv_sec--; diff->tv_usec = 1000 * 1000 - a->tv_usec + b->tv_usec; } else diff->tv_usec = b->tv_usec - a->tv_usec; return ret; } int64_t get_current_time(void) { time_t now; time(&now); return (int64_t)now; }