mirror of
https://github.com/curl/curl.git
synced 2026-08-25 13:33:36 +03:00
tool_writeout: fix %time{} output for %s
Now testing both %s and %% in test 1981 Reported-by: wulin-nudt on github Fixes #22038 Closes #22039
This commit is contained in:
parent
678e63934c
commit
e0c6f4d4d6
2 changed files with 31 additions and 10 deletions
|
|
@ -562,18 +562,39 @@ static const char *outtime(const char *ptr, /* %time{ ... */
|
|||
vlen = end - ptr;
|
||||
curlx_dyn_init(&format, 1024);
|
||||
|
||||
/* insert sub-seconds for %f */
|
||||
/* insert +0000 for %z because it is otherwise not portable */
|
||||
/* insert UTC for %Z because it is otherwise not portable */
|
||||
/* Insert:
|
||||
- sub-seconds for %f
|
||||
- epoch seconds for %s; strftime %s uses mktime() and assumes
|
||||
local time, which breaks UTC output on non-UTC hosts
|
||||
- +0000 for %z because it is otherwise not portable
|
||||
- UTC for %Z because it is otherwise not portable
|
||||
- Keep '%%' as-is so that strftime() makes a single % out of them
|
||||
*/
|
||||
for(i = 0; !result && i < vlen; i++) {
|
||||
if((i < vlen - 1) && ptr[i] == '%' &&
|
||||
((ptr[i + 1] == 'f') || ((ptr[i + 1] | 0x20) == 'z'))) {
|
||||
if(ptr[i + 1] == 'f')
|
||||
if((i < vlen - 1) && ptr[i] == '%') {
|
||||
switch(ptr[i + 1]) {
|
||||
case 'f':
|
||||
result = curlx_dyn_addf(&format, "%06u", usecs);
|
||||
else if(ptr[i + 1] == 'Z')
|
||||
break;
|
||||
case 's': {
|
||||
/* time_t might be either 32 or 64 bits big */
|
||||
curl_off_t tsecs = secs;
|
||||
result = curlx_dyn_addf(&format, "%" CURL_FORMAT_CURL_OFF_T, tsecs);
|
||||
break;
|
||||
}
|
||||
case 'Z':
|
||||
result = curlx_dyn_addn(&format, "UTC", 3);
|
||||
else
|
||||
break;
|
||||
case 'z':
|
||||
result = curlx_dyn_addn(&format, "+0000", 5);
|
||||
break;
|
||||
case '%':
|
||||
result = curlx_dyn_addn(&format, "%%", 2);
|
||||
break;
|
||||
default:
|
||||
result = curlx_dyn_addn(&format, &ptr[i], 1);
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue