summaryrefslogtreecommitdiff
path: root/src/compat/compat-gettimeofday.c
diff options
context:
space:
mode:
authorAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
committerAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
commit3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (patch)
treef29063da5bec4caf3853d49a22a09c8619eebd21 /src/compat/compat-gettimeofday.c
parentd53dba59e78da865c4fe820386ff2f4f76925f3b (diff)
New upstream version 2.4.0upstream/2.4.0
Diffstat (limited to 'src/compat/compat-gettimeofday.c')
-rw-r--r--src/compat/compat-gettimeofday.c98
1 files changed, 51 insertions, 47 deletions
diff --git a/src/compat/compat-gettimeofday.c b/src/compat/compat-gettimeofday.c
index 19feaae..d53e360 100644
--- a/src/compat/compat-gettimeofday.c
+++ b/src/compat/compat-gettimeofday.c
@@ -5,7 +5,7 @@
* packet encryption, packet authentication, and
* packet compression.
*
- * Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net>
+ * Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@ -48,12 +48,12 @@ static unsigned int last_msec = 0;
static int bt_last = 0;
static void
-gettimeofday_calibrate (void)
+gettimeofday_calibrate(void)
{
- const time_t t = time(NULL);
- const DWORD gtc = GetTickCount();
- gtc_base = t - gtc/1000;
- gtc_last = gtc;
+ const time_t t = time(NULL);
+ const DWORD gtc = GetTickCount();
+ gtc_base = t - gtc/1000;
+ gtc_last = gtc;
}
/*
@@ -62,68 +62,72 @@ gettimeofday_calibrate (void)
* more processor cycles than GetTickCount.
*/
int
-gettimeofday (struct timeval *tv, void *tz)
+gettimeofday(struct timeval *tv, void *tz)
{
- const DWORD gtc = GetTickCount();
- int bt = 0;
- time_t sec;
- unsigned int msec;
- const int backtrack_hold_seconds = 10;
+ const DWORD gtc = GetTickCount();
+ int bt = 0;
+ time_t sec;
+ unsigned int msec;
+ const int backtrack_hold_seconds = 10;
- (void)tz;
+ (void)tz;
- /* recalibrate at the dreaded 49.7 day mark */
- if (!gtc_base || gtc < gtc_last)
- gettimeofday_calibrate ();
- gtc_last = gtc;
+ /* recalibrate at the dreaded 49.7 day mark */
+ if (!gtc_base || gtc < gtc_last)
+ {
+ gettimeofday_calibrate();
+ }
+ gtc_last = gtc;
- sec = gtc_base + gtc / 1000;
- msec = gtc % 1000;
+ sec = gtc_base + gtc / 1000;
+ msec = gtc % 1000;
- if (sec == last_sec)
+ if (sec == last_sec)
{
- if (msec < last_msec)
- {
- msec = last_msec;
- bt = 1;
- }
+ if (msec < last_msec)
+ {
+ msec = last_msec;
+ bt = 1;
+ }
}
- else if (sec < last_sec)
+ else if (sec < last_sec)
{
- /* We try to dampen out backtracks of less than backtrack_hold_seconds.
- Larger backtracks will be passed through and dealt with by the
- TIME_BACKTRACK_PROTECTION code (if enabled) */
- if (sec > last_sec - backtrack_hold_seconds)
- {
- sec = last_sec;
- msec = last_msec;
- }
- bt = 1;
+ /* We try to dampen out backtracks of less than backtrack_hold_seconds.
+ * Larger backtracks will be passed through and dealt with by the
+ * TIME_BACKTRACK_PROTECTION code (if enabled) */
+ if (sec > last_sec - backtrack_hold_seconds)
+ {
+ sec = last_sec;
+ msec = last_msec;
+ }
+ bt = 1;
}
- tv->tv_sec = (long)last_sec = (long)sec;
- tv->tv_usec = (last_msec = msec) * 1000;
+ tv->tv_sec = (long)last_sec = (long)sec;
+ tv->tv_usec = (last_msec = msec) * 1000;
- if (bt && !bt_last)
- gettimeofday_calibrate ();
- bt_last = bt;
+ if (bt && !bt_last)
+ {
+ gettimeofday_calibrate();
+ }
+ bt_last = bt;
- return 0;
+ return 0;
}
-#else
+#else /* ifdef _WIN32 */
#ifdef HAVE_TIME_H
#include <time.h>
#endif
int
-gettimeofday (struct timeval *tv, void *tz)
+gettimeofday(struct timeval *tv, void *tz)
{
- (void)tz;
- tv->tv_sec = time(NULL);
- tv->tv_usec = 0;
- return 0;
+ (void)tz;
+ tv->tv_sec = time(NULL);
+ tv->tv_usec = 0;
+ return 0;
}
#endif /* _WIN32 */