From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14625 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Schoepe Newsgroups: gmane.linux.lib.musl.general Subject: printf doesn't respect locale Date: Mon, 9 Sep 2019 17:31:01 +0100 Message-ID: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="163106"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-14641-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 09 18:31:29 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i7MZc-000gJd-Ge for gllmg-musl@m.gmane.org; Mon, 09 Sep 2019 18:31:28 +0200 Original-Received: (qmail 1308 invoked by uid 550); 9 Sep 2019 16:31:26 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1273 invoked from network); 9 Sep 2019 16:31:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schoepe.org; s=google; h=mime-version:from:date:message-id:subject:to; bh=pkAKQtHssCHiM7zJfmOSeniY5QfIy+xgb3ARdVjHtBE=; b=h0tRVdxUvgZNWiPZQzl613Ry4fzItlzGoU2aECu8LlmvOp3lWLWG7ACVwlyq97FmU+ xiNpfgOplH2Uqa4xc/o8Yj+nl+a9tfTEz7eL+efABD9D5mwm5DwJyshs5ct+dXGsv5Pa RQoXDmkYxpvhZOxOyn5y6tEYW0DEJoyMA6RnM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=pkAKQtHssCHiM7zJfmOSeniY5QfIy+xgb3ARdVjHtBE=; b=pLLsFv1C95BHRmo7J2Vkqmo0/imI0gCd/bISsSNJWn4YFM9mZQWXb+aAyW9aqX80/k zK4Tq2TA6FjdNCpFdkCKkfMN+EGC6B+Zbbd685DZuvhpWLRbn8DfaByAp3JDc6Zf5pqM m0bk6GUjgfwHvIWBWpJmnI8Zb/FWV2El4HPGmb7EnCTRJfIiLmYCNNHRug7TGiFmVHzE tjmuT4gLslunLbzjRLj151Xk5JP5ZiDH/UAE6kSLoVFRUFjkAPhV6te2qRlEsVAyKTrn rzAFLyKvrpgpwNpJ+RViPQOXMC3PDKTwHTZ+/MAG54zGJg9551NA/lV3j/cB8yGNbXsB ZyMQ== X-Gm-Message-State: APjAAAXjlMugR3cWx9uFHG6Q6/Jqi0s8O/ttUPE8fA1EN5PsczHqP0ia 02m6HIQ4gJhf4LzIKtj/w48S0M+uvSomJ87KTvizrIPiQlw2eA== X-Google-Smtp-Source: APXvYqxoy+0FalL/2umDD+H5aj+Fj9Xhno3bfLU03ZNDo9nCGUPL7N5JXoF40ycEIpHGLN3mrtCXZhe/b3ki3PyeROw= X-Received: by 2002:ac8:454b:: with SMTP id z11mr24376648qtn.275.1568046673080; Mon, 09 Sep 2019 09:31:13 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:14625 Archived-At: 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 ( '.' )." 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 #include 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