On 2023-11-13 09:42, Corinna Vinschen wrote:
Hi Pedro,
On Nov 11 18:29, Pedro Luis Castedo Cepeda wrote:
OK. It's not a newlib problem but a GLib one as it is relaying on common but
non-standard strftime implementation details.
I attach a short program more focused in g_date_strftime implementation so
it can be evaluated if it worths addressing this corner case.
Tricky. I wonder what the GLib test is actually trying to accomplish.
POSIX has this to say:
RETURN VALUE
If the total number of resulting bytes including the terminating
null byte is not more than maxsize, these functions shall return
the number of bytes placed into the array pointed to by s, not
including the terminating NUL character. Otherwise, 0 shall be
returned and the contents of the array are unspecified.
ERRORS
No errors are defined.
But, and that's the big problem, POSIX does *not* provide for the
error case, because it doesn't allow an error like using an incorrect
format string to occur. Using an incorrect or undefined format code
is just not part of the standard.
And the Linux man page has an interesting extension to the above
POSIX RETURN VALUE section:
Note that the return value 0 does not necessarily indicate an
error. For example, in many locales %p yields an empty string. An
empty format string will likewise yield an empty string.
and additionally in the BUGS section:
If the output string would exceed max bytes, errno is not set.
This makes it impossible to distinguish this error case from cases
where the format string legitimately produces a zero-length
output string. POSIX.1-2001 does not specify any errno settings
for strftime().
So the below case tested by GLib is entirely out of scope of the
standard.
C 2023 draft says:
"7.29.3.5 The strftime function
...
Returns
8 If the total number of resulting characters including the terminating null
character is not more than maxsize, the strftime function returns the number of
characters placed into the array pointed to by s not including the terminating
null character. Otherwise, zero is returned and the members of the array have an
indeterminate representation."
GLib is not tested under Cygwin/newlib only VS2017 and Msys2-Mingw32 native
Windows:
https://gitlab.gnome.org/GNOME/glib/-/issues/2604
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2480/diffs
https://gitlab.gnome.org/malureau/glib/-/pipelines/366193/test_report
[may need to navigate not always obvious "tabs"]
Should raise a followup issue there - and point out it is not a Win32 issue - it
is another POSIX alternate libc issue - hosted under a Win64 environment.
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry