aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2022-08-31 15:32:45 +0000
committerWerner Koch <[email protected]>2022-08-31 15:32:45 +0000
commit0b91fa0f13fd3644d0be137ed02e006aa05b9501 (patch)
treeaa4c806e1abd96bb52d127ce484818f64626c11b
parentgpg: Emit STATUS_FAILURE for --require-compliance errors (diff)
downloadgnupg-0b91fa0f13fd3644d0be137ed02e006aa05b9501.tar.gz
gnupg-0b91fa0f13fd3644d0be137ed02e006aa05b9501.zip
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
-rw-r--r--common/gettime.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/common/gettime.c b/common/gettime.c
index 03c152fdb..3fe30cea3 100644
--- a/common/gettime.c
+++ b/common/gettime.c
@@ -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)