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:
Viktor Szakats 2025-12-13 00:16:58 +01:00
parent 74a2828279
commit c6988f9131
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
16 changed files with 59 additions and 44 deletions

View file

@ -40,6 +40,7 @@
#include "strdup.h"
#include "curlx/inet_pton.h"
#include "curlx/strparse.h"
#include "curlx/timeval.h"
#include "connect.h"
#define MAX_ALTSVC_LINE 4095
@ -241,7 +242,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
const char *dst6_post = "";
const char *src6_pre = "";
const char *src6_post = "";
CURLcode result = Curl_gmtime(as->expires, &stamp);
CURLcode result = curlx_gmtime(as->expires, &stamp);
if(result)
return result;
#ifdef USE_IPV6