mirror of
https://github.com/curl/curl.git
synced 2026-08-02 11:00:27 +03:00
tool_util: Improve Windows version of tvnow()
- Change tool_util.c tvnow() for Windows to match more closely to timeval.c Curl_now(). - Create a win32 init function for the tool, since some initialization is required for the tvnow() changes. Prior to this change the monotonic time function used by curl in Windows was determined at build-time and not runtime. That was a problem because when curl was built targeted for compatibility with old versions of Windows (eg _WIN32_WINNT < 0x0600) it would use GetTickCount which wraps every 49.7 days that Windows has been running. This change makes curl behave similar to libcurl's tvnow function, which determines at runtime whether the OS is Vista+ and if so calls QueryPerformanceCounter instead. (Note QueryPerformanceCounter is used because it has higher resolution than the more obvious candidate GetTickCount64). The changes to tvnow are basically a copy and paste but the types in some cases are different. Ref: https://github.com/curl/curl/issues/3309 Closes https://github.com/curl/curl/pull/4847
This commit is contained in:
parent
3735107d62
commit
1fc0617dcc
6 changed files with 72 additions and 33 deletions
|
|
@ -697,6 +697,32 @@ cleanup:
|
|||
return slist;
|
||||
}
|
||||
|
||||
LARGE_INTEGER Curl_freq;
|
||||
bool Curl_isVistaOrGreater;
|
||||
|
||||
CURLcode win32_init(void)
|
||||
{
|
||||
OSVERSIONINFOEXA osvi;
|
||||
unsigned __int64 mask = 0;
|
||||
unsigned char op = VER_GREATER_EQUAL;
|
||||
|
||||
memset(&osvi, 0, sizeof(osvi));
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
osvi.dwMajorVersion = 6;
|
||||
VER_SET_CONDITION(mask, VER_MAJORVERSION, op);
|
||||
VER_SET_CONDITION(mask, VER_MINORVERSION, op);
|
||||
|
||||
if(VerifyVersionInfoA(&osvi, (VER_MAJORVERSION | VER_MINORVERSION), mask))
|
||||
Curl_isVistaOrGreater = true;
|
||||
else if(GetLastError() == ERROR_OLD_WIN_VERSION)
|
||||
Curl_isVistaOrGreater = false;
|
||||
else
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
QueryPerformanceFrequency(&Curl_freq);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* MSDOS || WIN32 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue