avoid timeval.tv_sec a bit

This commit is contained in:
Daniel Stenberg 2025-08-01 16:40:38 +02:00
parent d537e9cfe7
commit 3c92c60a1f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -555,7 +555,8 @@ static const char *outtime(const char *ptr, /* %time{ ... */
#else
struct curltime cnow;
#endif
time_t now;
time_t secs;
unsigned int usecs;
size_t i;
size_t vlen;
CURLcode result = CURLE_OK;
@ -566,30 +567,26 @@ static const char *outtime(const char *ptr, /* %time{ ... */
cnow.tv_sec = time(NULL);
cnow.tv_usec = 0;
#endif
secs = cnow.tv_sec;
usecs = (unsigned int)cnow.tv_usec;
#ifdef DEBUGBUILD
{
const char *timestr = getenv("CURL_TIME");
if(timestr) {
curl_off_t val;
curlx_str_number(&timestr, &val, TIME_T_MAX);
#if SIZEOF_TIME_T < 5
cnow.tv_sec = (time_t)(val & 0xffffffff);
#else
cnow.tv_sec = (time_t)val;
#endif
cnow.tv_usec = (unsigned int)(val % 1000000);
secs = (time_t)val;
usecs = (unsigned int)(val % 1000000);
}
}
#endif
now = cnow.tv_sec;
vlen = end - ptr;
curlx_dyn_init(&format, 1024);
/* insert sub-seconds for %f */
for(i = 0; !result && i < vlen; i++) {
if((i < vlen - 1) && ptr[i] == '%' && ptr[i + 1] == 'f') {
result = curlx_dyn_addf(&format, "%06u",
(unsigned int)cnow.tv_usec);
result = curlx_dyn_addf(&format, "%06u", usecs);
i++;
continue;
}
@ -597,7 +594,7 @@ static const char *outtime(const char *ptr, /* %time{ ... */
}
if(!result) {
/* !checksrc! disable BANNEDFUNC 1 */
utc = gmtime(&now);
utc = gmtime(&secs);
strftime(output, sizeof(output), curlx_dyn_ptr(&format), utc);
fputs(output, stream);
curlx_dyn_free(&format);