common,w32: Fix an encoding problem of the printed timezone.

* common/gettime.c (w32_strftime) [W32]: New function.
(strftime) [W32]: New refinition macro.
--

GnuPG-bug-id: 5073
This commit is contained in:
Werner Koch 2022-08-31 17:32:45 +02:00
parent e05fb5ca37
commit 0b91fa0f13
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 40 additions and 1 deletions

View File

@ -676,6 +676,46 @@ isotimestamp (u32 stamp)
}
/* Windows version of strftime returning the string as utf-8. */
#ifdef HAVE_W32_SYSTEM
#define strftime(a,b,c,d) w32_strftime ((a),(b),(c),(d))
static size_t
w32_strftime (char *s, size_t max, const char *format, const struct tm *tm)
{
wchar_t *wformatbuf = NULL;
const wchar_t *wformat = L"%c %Z";
wchar_t wbuf[200];
size_t n;
char *buf;
if (strcmp (format, "%c %Z"))
{
log_debug (" comverted\n");
wformatbuf = utf8_to_wchar (format);
if (wformatbuf)
wformat = wformatbuf;
}
n = wcsftime (wbuf, sizeof wbuf, wformat, tm);
xfree (wformatbuf);
if (!n)
{
/* Most likely the buffer is too short - try ISO format instead. */
n = wcsftime (wbuf, sizeof wbuf, L"%Y-%m-%d %H:%M:%S", tm);
if (!n)
wcscpy (wbuf, L"[????" "-??" "-??]");
}
buf = wchar_to_utf8 (wbuf);
mem2str (s, buf? buf : "[????" "-??" "-??]", max);
xfree (buf);
return strlen (s) + 1;
}
#endif /*HAVE_W32_SYSTEM*/
/****************
* Note: this function returns local time
*/
@ -694,7 +734,6 @@ asctimestamp (u32 stamp)
strcpy (buffer, "????" "-??" "-??");
return buffer;
}
tp = localtime( &atime );
#ifdef HAVE_STRFTIME
# if defined(HAVE_NL_LANGINFO)