Package: mingw-w64-x86-64-dev
Version: 7.0.0-2
Severity: normal
Dear Maintainer,
I am trying to get a string representation of a date via strftime function.
For some reason the function call fails whenever format contains %e (day of
month with leading space instead of zero).
Also %z (time zone offset) results in "Central Europe Standard Time" (time zone
name) instead of +0100 or +0000 (the time zone offset).
Here is a small program "strftime.c" demonstrating the issue:
#include <inttypes.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
const char* get_str(char* buf, size_t max, const char* format, const struct tm*
lt)
{
snprintf(buf, max, "failure");
size_t sz = strftime(buf, max, format, lt);
if (sz==0 && buf[0]==0)
snprintf(buf, max, "(empty) errno=%d", errno);
return buf;
}
int main(){
const char* format[] = {"[%a]","[%e]","[%d]","[%-d]","[%#d]","[%b]",
"[%Y]",
"[%H]","[%M]","[%S]",
"[%z]", "[%Z]", "[%b%e,
%Y, %H:%M:%S %z]"};
const size_t format_sz = sizeof(format)/sizeof(format[0]);
// sec min hr DoM Mo Year DoW DoY dst
struct tm mytime = { 1, 2, 3, 5, 11-1, 2019-1900, 2, 308, 0 };
char buf[256];
for (unsigned int i=0; i<format_sz; ++i)
printf("%s: %s\n", format[i],
get_str(buf, sizeof(buf), format[i], &mytime));
}
Compile (three different versions: Windows 32bit, 64bit and Linux to compare):
i686-w64-mingw32-gcc -static -O3 -Wall -o strftime.exe strftime.c
x86_64-w64-mingw32-gcc -static -O3 -Wall -o strftime64.exe strftime.c
gcc -static -O3 -Wall -o strftime strftime.c
Execute:
./strftime.exe
[%a]: [Tue]
[%e]: (empty) errno=22
[%d]: [05]
[%-d]: (empty) errno=22
[%#d]: [5]
[%b]: [Nov]
[%Y]: [2019]
[%H]: [03]
[%M]: [02]
[%S]: [01]
[%z]: [Central Europe Standard Time]
[%Z]: [Central Europe Standard Time]
[%b%e, %Y, %H:%M:%S %z]: (empty) errno=22
./strftime64.exe
[%a]: [Tue]
[%e]: (empty) errno=22
[%d]: [05]
[%-d]: (empty) errno=22
[%#d]: [5]
[%b]: [Nov]
[%Y]: [2019]
[%H]: [03]
[%M]: [02]
[%S]: [01]
[%z]: [Central Europe Standard Time]
[%Z]: [Central Europe Standard Time]
[%b%e, %Y, %H:%M:%S %z]: (empty) errno=22
./strftime
[%a]: [Tue]
[%e]: [ 5]
[%d]: [05]
[%-d]: [5]
[%#d]: [05]
[%b]: [Nov]
[%Y]: [2019]
[%H]: [03]
[%M]: [02]
[%S]: [01]
[%z]: [+0000]
[%Z]: [CET]
[%b%e, %Y, %H:%M:%S %z]: [Nov 5, 2019, 03:02:01 +0000]
Note that [%e] yields a completely empty string, i.e. it does not even include
the square braces,
therefore %e is not just empty, but it is rather an error from strftime (also
errno 22 indicates "Invalid argument").
Also [%z] is just plain wrong.
The same program on Linux produces the expected (correct) results.
I am getting identical issues with wine and real Windows, also different
locales (LANG=en_US.UTF-8, LANG=C), meaning that it is somewhere in Windows
glibc implementation.
Also very old versions (from Jessie) have this issue, so it is probably a very
old upstream problem.
I think it is unlikely that something is wrong with my installations (I tried
on Jessie and current unstable).
I have some older static binaries (from 2014) where this issue does not appear
(sorry being vague about versions).
Moreover Windows documentation seems to coincide with Linux (there is nothing
special about %e and %z):
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=vs-2019
Best regards,
Marius
-- System Information:
Debian Release: bullseye/sid
APT prefers testing
APT policy: (900, 'testing'), (500, 'stable'), (50, 'unstable'), (1,
'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 5.2.0-3-amd64 (SMP w/8 CPU cores)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE,
TAINT_UNSIGNED_MODULE
Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8), LANGUAGE=
(charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages mingw-w64-x86-64-dev depends on:
ii mingw-w64-common 7.0.0-2
mingw-w64-x86-64-dev recommends no packages.
Versions of packages mingw-w64-x86-64-dev suggests:
ii wine64 4.0.2-1
-- no debconf information