Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 9 Sep 2019 17:39:10 +0100
From: Daniel Schoepe <daniel@...oepe.org>
To: musl@...ts.openwall.com
Subject: Re: printf doesn't respect locale

Small correction: The example works as the standard suggests on OSX,
but exhibits the same behavior as with musl with GNU libc as well.

On Mon, Sep 9, 2019 at 5:31 PM Daniel Schoepe <daniel@...oepe.org> wrote:
>
> Hi,
>
> I think I found a discrepancy between musl's behavior and the POSIX standard:
>
> According to the POSIX standard, the decimal separator used when using
> printf to print floating point numbers should come from the locale
> (https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html):
>
> "The radix character is defined in the current locale (category
> LC_NUMERIC). In the POSIX locale, or in a locale where the radix
> character is not defined, the radix character shall default to a
> <period> ( '.' )."
>
> However, it seems that in musl, a period is always used for printing
> floating point numbers. For example, the following program prints
> "12.0" instead of "12,0" (which is printed when using GNU libc):
>
> #include <stdio.h>
> #include <locale.h>
>
> int main(int argc, char **argv) {
>     setlocale(LC_ALL, "DE_de");
>     printf("%f\n", 12.0f);
> }
>
> This was tested using the latest git checkout of musl
> (a882841baf42e6a8b74cc33a239b84a9a79493db), compiled on Ubuntu 18.04
> using the musl-gcc script. It looks like the usage of "." as a
> separator is hardcoded in `fmt_fp`, for instance here:
> https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c#n392
>
> Best regards,
> Daniel

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.