* cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales
@ 2016-02-02 4:33 Tony Cook
2016-02-02 8:42 ` Achim Gratz
2016-02-08 12:37 ` Corinna Vinschen
0 siblings, 2 replies; 4+ messages in thread
From: Tony Cook @ 2016-02-02 4:33 UTC (permalink / raw)
To: cygwin
Hi list,
Simplified to a C program below, calls to sprintf() under the ps_AF
and ps_AF.utf8 locales are returning a value that doesn't match the
length of the formatted string:
tony@phobos ~
$ cat ps_AF.c
#include <stdio.h>
#include <locale.h>
#include <string.h>
int main(int argc, char **argv) {
char buf[100];
char *loc = argc > 1 ? argv[1] : "ps_AF";
const char *real_loc;
if (!(real_loc = setlocale(LC_NUMERIC, loc))) {
perror("setlocale");
return 1;
}
printf("locale %s\n", real_loc);
size_t len = sprintf(buf, "%g", 2.34);
printf("len %zu\n", len);
printf("strlen %zu\n", strlen(buf));
return 0;
}
tony@phobos ~
$ gcc -ops_AF.exe ps_AF.c
tony@phobos ~
$ ./ps_AF
locale ps_AF
len 4
strlen 5
tony@phobos ~
$ ./ps_AF ps_AF.utf8
locale ps_AF.utf8
len 4
strlen 5
tony@phobos ~
$ ./ps_AF en_US.utf8
locale en_US.utf8
len 4
strlen 4
tony@phobos ~
$ uname -a
CYGWIN_NT-6.1-WOW phobos 2.4.1(0.293/5/3) 2016-01-24 11:24 i686 Cygwin
The man pages and C standard could be read as sprintf() returning the
number of multi-byte characters, but if cygwin is intended to follow
Linux behaviour:
tony@mars:~/play$ gcc -ops_AF ps_AF.c
tony@mars:~/play$ ./ps_AF
locale ps_AF
len 5
strlen 5
tony@mars:~/play$ ./ps_AF ps_AF.utf8
locale ps_AF.utf8
len 5
strlen 5
tony@mars:~/play$ ./ps_AF en_AU.utf8
locale en_AU.utf8
len 4
strlen 4
tony@mars:~/play$ uname -a
Linux mars 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux
(and the decimal point under ps_AF on Linux is multi-byte, character
0x66b or ARABIC DECIMAL SEPARATOR.)
POSIX is less confusing and specifies:
Upon successful completion, the sprintf() function shall return the
number of bytes written to s, excluding the terminating null byte.
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html)
Tony
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales
2016-02-02 4:33 cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales Tony Cook
@ 2016-02-02 8:42 ` Achim Gratz
2016-02-08 12:37 ` Corinna Vinschen
1 sibling, 0 replies; 4+ messages in thread
From: Achim Gratz @ 2016-02-02 8:42 UTC (permalink / raw)
To: cygwin
Tony Cook <tony <at> develop-help.com> writes:
> Simplified to a C program below, calls to sprintf() under the ps_AF
> and ps_AF.utf8 locales are returning a value that doesn't match the
> length of the formatted string:
You've been digging at the Perl locale test fails?
:-)
Regards,
Achim.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales
2016-02-02 4:33 cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales Tony Cook
2016-02-02 8:42 ` Achim Gratz
@ 2016-02-08 12:37 ` Corinna Vinschen
1 sibling, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2016-02-08 12:37 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 1259 bytes --]
On Feb 2 15:32, Tony Cook wrote:
> Hi list,
>
> Simplified to a C program below, calls to sprintf() under the ps_AF
> and ps_AF.utf8 locales are returning a value that doesn't match the
> length of the formatted string:
>
> tony@phobos ~
> $ cat ps_AF.c
> #include <stdio.h>
> #include <locale.h>
> #include <string.h>
>
> int main(int argc, char **argv) {
> char buf[100];
> char *loc = argc > 1 ? argv[1] : "ps_AF";
> const char *real_loc;
> if (!(real_loc = setlocale(LC_NUMERIC, loc))) {
> perror("setlocale");
> return 1;
> }
> printf("locale %s\n", real_loc);
> size_t len = sprintf(buf, "%g", 2.34);
> printf("len %zu\n", len);
> printf("strlen %zu\n", strlen(buf));
>
> return 0;
> }
Thanks for the testcase.
> (and the decimal point under ps_AF on Linux is multi-byte, character
> 0x66b or ARABIC DECIMAL SEPARATOR.)
As on Cygwin. The problem was that Newlib's printf function didn't take
multibyte decimal points into account when computing the field size for
the output. I fixed that in the git repo.
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales
@ 2016-02-02 22:22 Tony Cook
0 siblings, 0 replies; 4+ messages in thread
From: Tony Cook @ 2016-02-02 22:22 UTC (permalink / raw)
To: cygwin
Achim Gratz said:
> You've been digging at the Perl locale test fails?
More that Karl Williamson was, I just turned it into a report.
Tony
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-08 12:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-02 4:33 cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales Tony Cook
2016-02-02 8:42 ` Achim Gratz
2016-02-08 12:37 ` Corinna Vinschen
2016-02-02 22:22 Tony Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).