Fix printf formatting with non-monetary grouping chars
PATCH v2 1/1 Fix printf formatting with non-monetary grouping chars
From: Eugene Loh <[email protected]>
Non-monetary grouping characters are used to separate groups of digits in numbers that are not monetary values. DTrace used to document support for printf formatting, using a single quote, for such grouping. Currently, support is largely implemented, but simply not working.
Add a setlocale() call to pick LC_NUMERIC up from environment variables.
Orabug: 30430270
--- cmd/dtrace.c | 5 +++- test/unittest/printf/tst.grouping-LC_ALL.r | 5 ++++ test/unittest/printf/tst.grouping-LC_ALL.sh | 29 +++++++++++++++++++ test/unittest/printf/tst.grouping-LC_ALL.x | 13 +++++++++ .../unittest/printf/tst.grouping-LC_NUMERIC.r | 5 ++++ .../printf/tst.grouping-LC_NUMERIC.sh | 29 +++++++++++++++++++ .../unittest/printf/tst.grouping-LC_NUMERIC.x | 13 +++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/unittest/printf/tst.grouping-LC_ALL.r create mode 100755 test/unittest/printf/tst.grouping-LC_ALL.sh create mode 100755 test/unittest/printf/tst.grouping-LC_ALL.x create mode 100644 test/unittest/printf/tst.grouping-LC_NUMERIC.r create mode 100755 test/unittest/printf/tst.grouping-LC_NUMERIC.sh create mode 100755 test/unittest/printf/tst.grouping-LC_NUMERIC.x
cmd/dtrace.c +4 -1
@@ -1,6 +1,6 @@/* * Oracle Linux DTrace. -* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */
@@ -9,6 +9,7 @@#include <sys/stat.h> #include <sys/wait.h> #include <sys/compiler.h> +#include <locale.h> #include <dtrace.h> #include <stdlib.h>
@@ -924,6 +925,8 @@ main(int argc, char *argv[])pid_t pid;struct dtrace_proc *proc; +setlocale (LC_NUMERIC ,"" ); + g_ofp = stdout; g_pname =basename (argv[0 ]);
test/unittest/printf/tst.grouping-LC_ALL.r new file +5 -0
@@ -0,0 +1,5 @@ +123456789 + +123,456,789 + +success
test/unittest/printf/tst.grouping-LC_ALL.sh new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. +# + +dtrace=$1 + +for mylocale in C en_US.utf8; do + export LC_ALL=$mylocale + + $dtrace $dt_flags -qs /dev/stdin << EOF + BEGIN + { + printf("%'d\n", 123456789); + exit(0); + } +EOF + if [ $? -ne 0 ]; then + echo ERROR: dtrace + locale + exit 1 + fi +done + +echo success +exit 0
test/unittest/printf/tst.grouping-LC_ALL.x new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. + +if locale -a | grep -q en_US.utf8 ; then + exit 0 +fi + +echo the en_US.utf8 locale was not found +exit 2
test/unittest/printf/tst.grouping-LC_NUMERIC.r new file +5 -0
@@ -0,0 +1,5 @@ +123456789 + +123,456,789 + +success
test/unittest/printf/tst.grouping-LC_NUMERIC.sh new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. +# + +dtrace=$1 + +for mylocale in C en_US.utf8; do + export LC_NUMERIC=$mylocale + + $dtrace $dt_flags -qs /dev/stdin << EOF + BEGIN + { + printf("%'d\n", 123456789); + exit(0); + } +EOF + if [ $? -ne 0 ]; then + echo ERROR: dtrace + locale + exit 1 + fi +done + +echo success +exit 0
test/unittest/printf/tst.grouping-LC_NUMERIC.x new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. + +if locale -a | grep -q en_US.utf8 ; then + exit 0 +fi + +echo the en_US.utf8 locale was not found +exit 2
Signature · 1 line
2.47.3
Quoted 11 lines · On Fri, Jan 16, 2026 at 04:14:32PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Non-monetary grouping characters are used to separate groups of digits in numbers that are not monetary values. DTrace used to document support for printf formatting, using a single quote, for such grouping. Currently, support is largely implemented, but simply not working.
Add a
setlocale()call to pickLC_NUMERICup from environment variables.Orabug: 30430270
Signed-off-by Eugene Loh <[email protected]>
Quoted 178 lines
--- cmd/dtrace.c | 5 +++- test/unittest/printf/tst.grouping-LC_ALL.r | 5 ++++ test/unittest/printf/tst.grouping-LC_ALL.sh | 29 +++++++++++++++++++ test/unittest/printf/tst.grouping-LC_ALL.x | 13 +++++++++ .../unittest/printf/tst.grouping-LC_NUMERIC.r | 5 ++++ .../printf/tst.grouping-LC_NUMERIC.sh | 29 +++++++++++++++++++ .../unittest/printf/tst.grouping-LC_NUMERIC.x | 13 +++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/unittest/printf/tst.grouping-LC_ALL.r create mode 100755 test/unittest/printf/tst.grouping-LC_ALL.sh create mode 100755 test/unittest/printf/tst.grouping-LC_ALL.x create mode 100644 test/unittest/printf/tst.grouping-LC_NUMERIC.r create mode 100755 test/unittest/printf/tst.grouping-LC_NUMERIC.sh create mode 100755 test/unittest/printf/tst.grouping-LC_NUMERIC.xcmd/dtrace.c +4
-1@@ -1,6 +1,6 @@/* * Oracle Linux DTrace. -* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */ @@ -9,6 +9,7 @@#include <sys/stat.h> #include <sys/wait.h> #include <sys/compiler.h> +#include <locale.h> #include <dtrace.h> #include <stdlib.h> @@ -924,6 +925,8 @@ main(int argc, char *argv[])pid_t pid;struct dtrace_proc *proc; +setlocale (LC_NUMERIC ,"" ); + g_ofp = stdout; g_pname =basename (argv[0 ]);test/unittest/printf/tst.grouping-LC_ALL.r new file +5
-0@@ -0,0 +1,5 @@ +123456789 + +123,456,789 + +successtest/unittest/printf/tst.grouping-LC_ALL.sh new file +29
-0@@ -0,0 +1,29 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. +# + +dtrace=$1 + +for mylocale in C en_US.utf8; do + export LC_ALL=$mylocale + + $dtrace $dt_flags -qs /dev/stdin << EOF + BEGIN + { + printf("%'d\n", 123456789); + exit(0); + } +EOF + if [ $? -ne 0 ]; then + echo ERROR: dtrace + locale + exit 1 + fi +done + +echo success +exit 0test/unittest/printf/tst.grouping-LC_ALL.x new file +13
-0@@ -0,0 +1,13 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. + +if locale -a | grep -q en_US.utf8 ; then + exit 0 +fi + +echo the en_US.utf8 locale was not found +exit 2test/unittest/printf/tst.grouping-LC_NUMERIC.r new file +5
-0@@ -0,0 +1,5 @@ +123456789 + +123,456,789 + +successtest/unittest/printf/tst.grouping-LC_NUMERIC.sh new file +29
-0@@ -0,0 +1,29 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. +# + +dtrace=$1 + +for mylocale in C en_US.utf8; do + export LC_NUMERIC=$mylocale + + $dtrace $dt_flags -qs /dev/stdin << EOF + BEGIN + { + printf("%'d\n", 123456789); + exit(0); + } +EOF + if [ $? -ne 0 ]; then + echo ERROR: dtrace + locale + exit 1 + fi +done + +echo success +exit 0test/unittest/printf/tst.grouping-LC_NUMERIC.x new file +13
-0@@ -0,0 +1,13 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. + +if locale -a | grep -q en_US.utf8 ; then + exit 0 +fi + +echo the en_US.utf8 locale was not found +exit 2Signature · 1 line
2.47.3