From nobody Sat Nov 05 00:31:09 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N3z1n4CqMz4hB76; Sat, 5 Nov 2022 00:31:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N3z1n3X82z3LxM; Sat, 5 Nov 2022 00:31:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667608269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LrIoFpXwBXG7liBSqjiuiFnj9wq5mif5fJWf1WaOpVw=; b=PlHfui4ZtDreTD2FhypM8ysfb9KAU9r9kiUargByThXKCpjG7lNR1On5YRK49EfiZ1AcJs r1FD1vGX5FM/2lMg3itp06HIc3k5/EAnZAfW0O5Z8MY4DBOKR/xc5ZYs6bompmNOQUmMgW 8O3ZnFJfos1u3ZKBH5Cepmb6FX4OjeHOOHcgM87CjkVzV+E4McJIr7VwAJAOTkJl/PgjVY 2Xi/K0nRqcQxEdFddgC3zGNkLbxX0iG6ZvGJIGxiI1PO2aCkjWQfpmvQCHPcPk8libzMkc JI6Fd9McgNTgNMNEad2kFXxV9G7M9ofhYXNhbJn85dmg1dpnhaMSuFBfhKCDXw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N3z1n2Z2yzM69; Sat, 5 Nov 2022 00:31:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2A50V94i071130; Sat, 5 Nov 2022 00:31:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A50V97Q071129; Sat, 5 Nov 2022 00:31:09 GMT (envelope-from git) Date: Sat, 5 Nov 2022 00:31:09 GMT Message-Id: <202211050031.2A50V97Q071129@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: bd847e46f17a - stable/13 - strfmon_l: Use specified locale for number formatting List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bd847e46f17af8fe5a4f0db017d28289b813dadb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667608269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LrIoFpXwBXG7liBSqjiuiFnj9wq5mif5fJWf1WaOpVw=; b=kl+KZnLDIKJbIKXquN4WWzBYJ02KX/XAKqX9l4mugOqpjhsgKIbDYrDtPPtwSAjMgwgWdB f6J02iOc4d07+YlZkWh/5x5eBZbKEIWe0//AicliGeew0VJvxICG6Ydz8t0RiJ3U1/+q1F KYJFS1h3T0NIdDLQb3tvNnVI6fNEvmN601F4UHH1sBLQCuPWWReSrtzS4g0iTfIuVlLl+p 0OyA9JIzNOclZV72zd6PNmc7Orl6lR1a7TgTYZyz55lx6M6C5NpTfd7hxFHzp/n9L0fTVL +AIms8ECku5NIOLXMFVe+xyTXJ+JUN8GdhWo8j7zFa5Nwvj36V3QWIMzJMhRzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667608269; a=rsa-sha256; cv=none; b=eV580xQmlykDvreklbo7IkTwkZmJt19mNKU8Z7zZWymKqd3N17CqAI01c+JixQX3g9T15s Qpg5KWBBSdeOODe3sLMCkkAs8ddhuyiakP3D6kB+qdAkt/cchQG+xoc4mBmWE+609DfFRA r/Knmm7TlZJesqGFHsQAqZxu0fS0CLu9b79Gbv4dCsAy8YApAp2i2fp1m/julcsliqeYcm aisb+bJz/8JPwMnTVdGZaujXquqjQ4UxLF0/VYznL98nH+6vUD1DXFBShR7/rjocpc9zLs HSomAU0iiHP0lZ7pgzd5K2T8l8ktXy/qLxgzucHflz95HQwhoi3cPK6FH1zKng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=bd847e46f17af8fe5a4f0db017d28289b813dadb commit bd847e46f17af8fe5a4f0db017d28289b813dadb Author: Jose Luis Duran AuthorDate: 2022-10-28 01:24:48 +0000 Commit: Konstantin Belousov CommitDate: 2022-11-05 00:30:39 +0000 strfmon_l: Use specified locale for number formatting (cherry picked from commit 621bf91893ad96c2ec46e603bf4c5b8762e3f730) --- lib/libc/stdlib/strfmon.c | 47 ++++++++++++++++++------------------ lib/libc/tests/stdlib/strfmon_test.c | 4 +-- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index 5436bd6ec78e..dd1a69dd6d7a 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -71,9 +71,9 @@ __FBSDID("$FreeBSD$"); PRINT(*tmps++); \ } while (0) -#define GET_NUMBER(VAR) do { \ +#define GET_NUMBER(VAR, LOC) do { \ VAR = 0; \ - while (isdigit((unsigned char)*fmt)) { \ + while (isdigit_l((unsigned char)*fmt, LOC)) { \ if (VAR > INT_MAX / 10) \ goto e2big_error; \ VAR *= 10; \ @@ -98,9 +98,10 @@ __FBSDID("$FreeBSD$"); groups++; \ } while (0) -static void __setup_vars(int, char *, char *, char *, char **); -static int __calc_left_pad(int, char *); -static char *__format_grouped_double(double, int *, int, int, int); +static void __setup_vars(int, char *, char *, char *, char **, struct lconv *); +static int __calc_left_pad(int, char *, struct lconv *); +static char *__format_grouped_double(double, int *, int, int, int, + struct lconv *, locale_t); static ssize_t vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, @@ -194,8 +195,8 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, } /* field Width */ - if (isdigit((unsigned char)*fmt)) { - GET_NUMBER(width); + if (isdigit_l((unsigned char)*fmt, loc)) { + GET_NUMBER(width, loc); /* Do we have enough space to put number with * required width ? */ @@ -205,18 +206,18 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* Left precision */ if (*fmt == '#') { - if (!isdigit((unsigned char)*++fmt)) + if (!isdigit_l((unsigned char)*++fmt, loc)) goto format_error; - GET_NUMBER(left_prec); + GET_NUMBER(left_prec, loc); if ((unsigned int)left_prec >= maxsize - (dst - s)) goto e2big_error; } /* Right precision */ if (*fmt == '.') { - if (!isdigit((unsigned char)*++fmt)) + if (!isdigit_l((unsigned char)*++fmt, loc)) goto format_error; - GET_NUMBER(right_prec); + GET_NUMBER(right_prec, loc); if ((unsigned int)right_prec >= maxsize - (dst - s) - left_prec) goto e2big_error; @@ -262,8 +263,8 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* fill left_prec with amount of padding chars */ if (left_prec >= 0) { pad_size = __calc_left_pad((flags ^ IS_NEGATIVE), - currency_symbol) - - __calc_left_pad(flags, currency_symbol); + currency_symbol, lc) - + __calc_left_pad(flags, currency_symbol, lc); if (pad_size < 0) pad_size = 0; } @@ -271,14 +272,14 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, if (asciivalue != NULL) free(asciivalue); asciivalue = __format_grouped_double(value, &flags, - left_prec, right_prec, pad_char); + left_prec, right_prec, pad_char, lc, loc); if (asciivalue == NULL) goto end_error; /* errno already set */ /* to ENOMEM by malloc() */ /* set some variables for later use */ __setup_vars(flags, &cs_precedes, &sep_by_space, - &sign_posn, &signstr); + &sign_posn, &signstr, lc); /* * Description of some LC_MONETARY's values: @@ -422,10 +423,8 @@ end_error: static void __setup_vars(int flags, char *cs_precedes, char *sep_by_space, - char *sign_posn, char **signstr) + char *sign_posn, char **signstr, struct lconv *lc) { - struct lconv *lc = localeconv(); - if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { *cs_precedes = lc->int_n_cs_precedes; *sep_by_space = lc->int_n_sep_by_space; @@ -460,12 +459,13 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, } static int -__calc_left_pad(int flags, char *cur_symb) +__calc_left_pad(int flags, char *cur_symb, struct lconv *lc) { char cs_precedes, sep_by_space, sign_posn, *signstr; int left_chars = 0; - __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, + &signstr, lc); if (cs_precedes != 0) { left_chars += strlen(cur_symb); @@ -515,7 +515,7 @@ get_groups(int size, char *grouping) /* convert double to locale-encoded string */ static char * __format_grouped_double(double value, int *flags, - int left_prec, int right_prec, int pad_char) + int left_prec, int right_prec, int pad_char, struct lconv *lc, locale_t loc) { char *rslt; @@ -527,7 +527,6 @@ __format_grouped_double(double value, int *flags, int padded; - struct lconv *lc = localeconv(); char *grouping; const char *decimal_point; const char *thousands_sep; @@ -566,8 +565,8 @@ __format_grouped_double(double value, int *flags, left_prec += get_groups(left_prec, grouping); /* convert to string */ - avalue_size = asprintf(&avalue, "%*.*f", left_prec + right_prec + 1, - right_prec, value); + avalue_size = asprintf_l(&avalue, loc, "%*.*f", + left_prec + right_prec + 1, right_prec, value); if (avalue_size < 0) return (NULL); diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index dcad17d3dbfd..224b3f44911e 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -224,8 +224,8 @@ ATF_TC_BODY(strfmon_l, tc) const char *expected; } tests[] = { { "C", "[ **1234.57 ] [ **1234.57 ]" }, - { "de_DE.UTF-8", "[ €**1234.57 ] [ EUR**1234.57 ]" }, /* XXX */ - { "en_GB.UTF-8", "[ £**1234.57 ] [ GBP**1234.57 ]" }, /* XXX */ + { "de_DE.UTF-8", "[ **1234,57 €] [ **1.234,57 EUR]" }, + { "en_GB.UTF-8", "[ £**1234.57] [ GBP**1,234.57]" }, }; locale_t loc; size_t i;