mirror of
https://github.com/curl/curl.git
synced 2026-08-26 02:43:31 +03:00
curlx: move Curl_gmtime(), use gmtime_s() on Windows
Move `Curl_gmtime()` to curlx and rename to `curlx_gmtime()`. Then call
the internal wrapper also from the curl tool, to avoid using the banned
`gmtime()` directly, and using better, thread-safe alternatives when
available.
Windows `gmtime_s()` requires mingw-w64 v4+ or MSVC. Use local
workaround to also support mingw-w64 v3. `gmtime_s()` also makes
defining `_CRT_SECURE_NO_WARNINGS` unnecessary.
Also:
- lib: drop unused `parsedate.h` includes.
- drop redundant cast from `gmtime_r()` result.
- autotools: reverse condition in the proto detection to avoid
misleading readers. (the condition plays no role in detection.)
- note Windows XP's default `msvcrt.dll` doesn't offer secure CRT APIs.
XP likely needs a newer version of this DLL, or may not run.
Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/gmtime-gmtime32-gmtime64
https://learn.microsoft.com/cpp/c-runtime-library/reference/gmtime-s-gmtime32-s-gmtime64-s
https://pubs.opengroup.org/onlinepubs/9799919799/functions/gmtime.html
https://linux.die.net/man/3/gmtime_r
Ref: #19957 (for `localtime_r()`)
Follow-up to 54d9f060b4
Closes #19955
This commit is contained in:
parent
74a2828279
commit
c6988f9131
16 changed files with 59 additions and 44 deletions
|
|
@ -548,7 +548,6 @@ static const char *outtime(const char *ptr, /* %time{ ... */
|
|||
ptr += 6;
|
||||
end = strchr(ptr, '}');
|
||||
if(end) {
|
||||
struct tm *utc;
|
||||
struct dynbuf format;
|
||||
char output[256]; /* max output time length */
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
|
|
@ -602,10 +601,10 @@ static const char *outtime(const char *ptr, /* %time{ ... */
|
|||
result = curlx_dyn_addn(&format, &ptr[i], 1);
|
||||
}
|
||||
if(!result) {
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
utc = gmtime(&secs);
|
||||
if(curlx_dyn_len(&format) && utc &&
|
||||
strftime(output, sizeof(output), curlx_dyn_ptr(&format), utc))
|
||||
struct tm utc;
|
||||
result = curlx_gmtime(secs, &utc);
|
||||
if(curlx_dyn_len(&format) && !result &&
|
||||
strftime(output, sizeof(output), curlx_dyn_ptr(&format), &utc))
|
||||
fputs(output, stream);
|
||||
curlx_dyn_free(&format);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue