diff options
author | Jay Satiro <raysatiro@yahoo.com> | 2020-01-24 03:34:52 -0500 |
---|---|---|
committer | Jay Satiro <raysatiro@yahoo.com> | 2020-02-18 15:52:13 -0500 |
commit | 1fc0617dccc3fa138235f219e2eaa7b405d1162e (patch) | |
tree | 76d86ee1145e2e8dad7dc16f95c4a4b14f88898e /src/tool_main.c | |
parent | 3735107d62ad28d6e25bd94109ab9f2454c22116 (diff) |
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
Diffstat (limited to 'src/tool_main.c')
-rw-r--r-- | src/tool_main.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/tool_main.c b/src/tool_main.c index 06923c332..047796b6c 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -279,6 +279,24 @@ int main(int argc, char *argv[]) struct GlobalConfig global; memset(&global, 0, sizeof(global)); +#ifdef WIN32 + /* Undocumented diagnostic option to list the full paths of all loaded + modules. This is purposely pre-init. */ + if(argc == 2 && !strcmp(argv[1], "--dump-module-paths")) { + struct curl_slist *item, *head = GetLoadedModulePaths(); + for(item = head; item; item = item->next) + printf("%s\n", item->data); + curl_slist_free_all(head); + return head ? 0 : 1; + } + /* win32_init must be called before other init routines. */ + result = win32_init(); + if(result) { + fprintf(stderr, "curl: (%d) Windows-specific init failed.\n", result); + return result; + } +#endif + /* Perform any platform-specific terminal configuration */ configure_terminal(); @@ -294,21 +312,6 @@ int main(int argc, char *argv[]) /* Initialize the curl library - do not call any libcurl functions before this point */ result = main_init(&global); - -#ifdef WIN32 - /* Undocumented diagnostic option to list the full paths of all loaded - modules, regardless of whether or not initialization succeeded. */ - if(argc == 2 && !strcmp(argv[1], "--dump-module-paths")) { - struct curl_slist *item, *head = GetLoadedModulePaths(); - for(item = head; item; item = item->next) { - printf("%s\n", item->data); - } - curl_slist_free_all(head); - if(!result) - main_free(&global); - } - else -#endif /* WIN32 */ if(!result) { /* Start our curl operation */ result = operate(&global, argc, argv); |