/* * Copyright (C) 2005-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ #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. * * \param b Minuend. * \param a Subtrahend. * \param diff Result pointer. * * If \a diff is not \p NULL, it contains the absolute value |\a b - \a a| on * return. * * \return If \a b < \a a, this function returns -1, otherwise it returns 1. */ 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); DSS_DEBUG_LOG(("now: %jd\n", (intmax_t)now)); return (int64_t)now; }