curl: make global truly global

The GlobalConfig only exists in a single instance and it has worked like
this since the dawn of time. It is about time we stop passing around
pointers to what was already essentially a global object and instead
just use a... global.

It simplifies things.

Closes #18213
This commit is contained in:
Daniel Stenberg 2025-08-06 23:18:46 +02:00
parent 2d9f24bf24
commit 3b40128b0f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
42 changed files with 473 additions and 626 deletions

View file

@ -32,8 +32,7 @@
#endif
/* Returns 0 on success, non-zero on file problems */
int getfiletime(const char *filename, struct GlobalConfig *global,
curl_off_t *stamp)
int getfiletime(const char *filename, curl_off_t *stamp)
{
int rc = 1;
@ -56,21 +55,21 @@ int getfiletime(const char *filename, struct GlobalConfig *global,
| ((curl_off_t)ft.dwHighDateTime) << 32;
if(converted < 116444736000000000)
warnf(global, "Failed to get filetime: underflow");
warnf("Failed to get filetime: underflow");
else {
*stamp = (converted - 116444736000000000) / 10000000;
rc = 0;
}
}
else {
warnf(global, "Failed to get filetime: "
warnf("Failed to get filetime: "
"GetFileTime failed: GetLastError %u",
(unsigned int)GetLastError());
}
CloseHandle(hfile);
}
else if(GetLastError() != ERROR_FILE_NOT_FOUND) {
warnf(global, "Failed to get filetime: "
warnf("Failed to get filetime: "
"CreateFile failed: GetLastError %u",
(unsigned int)GetLastError());
}
@ -81,14 +80,13 @@ int getfiletime(const char *filename, struct GlobalConfig *global,
rc = 0;
}
else
warnf(global, "Failed to get filetime: %s", strerror(errno));
warnf("Failed to get filetime: %s", strerror(errno));
#endif
return rc;
}
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || defined(_WIN32)
void setfiletime(curl_off_t filetime, const char *filename,
struct GlobalConfig *global)
void setfiletime(curl_off_t filetime, const char *filename)
{
if(filetime >= 0) {
/* Windows utime() may attempt to adjust the Unix GMT file time by a daylight
@ -101,7 +99,7 @@ void setfiletime(curl_off_t filetime, const char *filename,
/* 910670515199 is the maximum Unix filetime that can be used as a
Windows FILETIME without overflow: 30827-12-31T23:59:59. */
if(filetime > 910670515199) {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: overflow", filetime);
curlx_unicodefree(tchar_filename);
return;
@ -119,14 +117,14 @@ void setfiletime(curl_off_t filetime, const char *filename,
ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
ft.dwHighDateTime = (DWORD)(converted >> 32);
if(!SetFileTime(hfile, NULL, &ft, &ft)) {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: SetFileTime failed: GetLastError %u",
filetime, (unsigned int)GetLastError());
}
CloseHandle(hfile);
}
else {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: CreateFile failed: GetLastError %u",
filetime, (unsigned int)GetLastError());
}
@ -136,7 +134,7 @@ void setfiletime(curl_off_t filetime, const char *filename,
times[0].tv_sec = times[1].tv_sec = (time_t)filetime;
times[0].tv_usec = times[1].tv_usec = 0;
if(utimes(filename, times)) {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on '%s': %s", filetime, filename, strerror(errno));
}
@ -145,7 +143,7 @@ void setfiletime(curl_off_t filetime, const char *filename,
times.actime = (time_t)filetime;
times.modtime = (time_t)filetime;
if(utime(filename, &times)) {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on '%s': %s", filetime, filename, strerror(errno));
}
#endif