aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-11-03 19:31:12 +0100
committerWerner Koch <wk@gnupg.org>2020-11-03 19:32:11 +0100
commite8aae18b997b3fdbfac86c644be94044aa67224d (patch)
tree6ea4e79c931d9eb30ef6689ac57eeca2e34961ef
parentd1f2a6d9f71cf50318f4891c84aeedb975553896 (diff)
downloadgnupg-e8aae18b997b3fdbfac86c644be94044aa67224d.tar.gz
w32: Fix strftime problem on Windows.
* common/gettime.c: Include locale.h. (asctimestamp): Increase buffer. On Windows use setlocale. -- GnuPG-bug-id: 5073 Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r--common/gettime.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/common/gettime.c b/common/gettime.c
index 4ad99f54d..03c152fdb 100644
--- a/common/gettime.c
+++ b/common/gettime.c
@@ -31,6 +31,9 @@
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
@@ -679,9 +682,9 @@ isotimestamp (u32 stamp)
const char *
asctimestamp (u32 stamp)
{
- static char buffer[50];
+ static char buffer[80];
#if defined (HAVE_STRFTIME) && defined (HAVE_NL_LANGINFO)
- static char fmt[50];
+ static char fmt[80];
#endif
struct tm *tp;
time_t atime = stamp;
@@ -707,6 +710,32 @@ asctimestamp (u32 stamp)
zone at all. */
strftime (buffer, DIM(buffer)-1, "%c", tp);
# else
+# if HAVE_W32_SYSTEM
+ {
+ static int done;
+
+ if (!done)
+ {
+ /* The locale names as used by Windows are in the form
+ * "German_Germany.1252" or "German_Austria.1252" with
+ * alternate names similar to Unix, e.g. "de-DE". However
+ * that is the theory. On current Windows and Mingw the
+ * alternate names do not work. We would need a table to map
+ * them from the short names as provided by gpgrt to the long
+ * names and append some code page. For now we use "" and
+ * take the locale from the user's system settings. Thus the
+ * standard Unix envvars don't work for time and may mismatch
+ * with the string translations. The new UCRT available since
+ * 2018 has a lot of additional support but that will for sure
+ * break other things. We should move to ISO strings to get
+ * rid of such problems. */
+ setlocale (LC_TIME, "");
+ done = 1;
+ /* log_debug ("LC_ALL now '%s'\n", setlocale (LC_ALL, NULL)); */
+ /* log_debug ("LC_TIME now '%s'\n", setlocale (LC_TIME, NULL)); */
+ }
+ }
+# endif
/* FIXME: we should check whether the locale appends a " %Z" These
* locales from glibc don't put the " %Z": fi_FI hr_HR ja_JP lt_LT
* lv_LV POSIX ru_RU ru_SU sv_FI sv_SE zh_CN. */