diff --git a/lib/util.c b/lib/util.c index ceace41f1..843efc441 100644 --- a/lib/util.c +++ b/lib/util.c @@ -52,6 +52,7 @@ #include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" +#include "lib/timer.h" /*** global variables ****************************************************************************/ @@ -1451,3 +1452,28 @@ mc_replace_error (GError ** dest, int code, const char *format, ...) } /* --------------------------------------------------------------------------------------------- */ + +/** + * Returns if the given duration has elapsed since the given timestamp, + * and if it has then updates the timestamp. + * + * @param timestamp the last timestamp in microseconds, updated if the given time elapsed + * @param deleay amount of time in microseconds + + * @return TRUE if clock skew detected, FALSE otherwise + */ +gboolean +mc_time_elapsed (guint64 * timestamp, guint64 delay) +{ + guint64 now; + + now = mc_timer_elapsed (mc_global.timer); + + if (now >= *timestamp && now < *timestamp + delay) + return FALSE; + + *timestamp = now; + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/util.h b/lib/util.h index 213f7d8fa..a8acfed82 100644 --- a/lib/util.h +++ b/lib/util.h @@ -249,6 +249,8 @@ char *mc_build_filenamev (const char *first_element, va_list args); void mc_propagate_error (GError ** dest, int code, const char *format, ...); void mc_replace_error (GError ** dest, int code, const char *format, ...); +gboolean mc_time_elapsed (guint64 * timestamp, guint64 delay); + /*** inline functions **************************************************/ static inline gboolean