summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/timeval.c
diff options
context:
space:
mode:
authordartraiden <wowemuh@gmail.com>2019-02-10 02:02:38 +0300
committerdartraiden <wowemuh@gmail.com>2019-02-10 02:06:58 +0300
commiteee2c11f79a8958e65cc485af1e7afcbd394db1e (patch)
tree9ab4418393997629ef9dc7ae78089cbece595d0c /libs/libcurl/src/timeval.c
parent33d2c8e71902aa37d3fc978cb91e0a842a600960 (diff)
libcurl: update to 7.64
Diffstat (limited to 'libs/libcurl/src/timeval.c')
-rw-r--r--libs/libcurl/src/timeval.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/libs/libcurl/src/timeval.c b/libs/libcurl/src/timeval.c
index dce1a761e8..2569f175c3 100644
--- a/libs/libcurl/src/timeval.c
+++ b/libs/libcurl/src/timeval.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -21,29 +21,45 @@
***************************************************************************/
#include "timeval.h"
+#include "system_win32.h"
#if defined(WIN32) && !defined(MSDOS)
struct curltime Curl_now(void)
{
- /*
- ** GetTickCount() is available on _all_ Windows versions from W95 up
- ** to nowadays. Returns milliseconds elapsed since last system boot,
- ** increases monotonically and wraps once 49.7 days have elapsed.
- */
struct curltime now;
-#if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
- (_WIN32_WINNT < _WIN32_WINNT_VISTA) || \
- (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR))
- DWORD milliseconds = GetTickCount();
- now.tv_sec = milliseconds / 1000;
- now.tv_usec = (milliseconds % 1000) * 1000;
-#else
- ULONGLONG milliseconds = GetTickCount64();
- now.tv_sec = (time_t) (milliseconds / 1000);
- now.tv_usec = (unsigned int) (milliseconds % 1000) * 1000;
+ static LARGE_INTEGER freq;
+ static int isVistaOrGreater = -1;
+ if(isVistaOrGreater == -1) {
+ if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
+ VERSION_GREATER_THAN_EQUAL)) {
+ isVistaOrGreater = 1;
+ QueryPerformanceFrequency(&freq);
+ }
+ else
+ isVistaOrGreater = 0;
+ }
+ if(isVistaOrGreater == 1) { /* QPC timer might have issues pre-Vista */
+ LARGE_INTEGER count;
+ QueryPerformanceCounter(&count);
+ now.tv_sec = (time_t)(count.QuadPart / freq.QuadPart);
+ now.tv_usec =
+ (int)((count.QuadPart % freq.QuadPart) * 1000000 / freq.QuadPart);
+ }
+ else {
+ /* Disable /analyze warning that GetTickCount64 is preferred */
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:28159)
+#endif
+ DWORD milliseconds = GetTickCount();
+#if defined(_MSC_VER)
+#pragma warning(pop)
#endif
+ now.tv_sec = milliseconds / 1000;
+ now.tv_usec = (milliseconds % 1000) * 1000;
+ }
return now;
}
@@ -180,7 +196,7 @@ struct curltime Curl_now(void)
*/
timediff_t Curl_timediff(struct curltime newer, struct curltime older)
{
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
if(diff >= (TIME_MAX/1000))
return TIME_MAX;
else if(diff <= (TIME_MIN/1000))
@@ -194,7 +210,7 @@ timediff_t Curl_timediff(struct curltime newer, struct curltime older)
*/
timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
{
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
if(diff >= (TIME_MAX/1000000))
return TIME_MAX;
else if(diff <= (TIME_MIN/1000000))