Subject: Re: [PATCH] printf: add %#s alias to %b

From: Pádraig Brady <[email-masked]>
Date: Thu, 31 Aug 2023 21:48:09 +0100

On 31/08/2023 19:31, Eric Blake wrote:
> POSIX Issue 8 will be obsoleting %b (escape sequence interpolation) so
> that future Issue 9 can change to having %b (binary literal output)
> that aligns with C2x.  But since escape interpolation may still remain
> useful, POSIX suggested %#s (which is undefined in all versions of C)
> as a possible alias for the older %b behavior.
> 
> * src/printf.c (print_formatted, usage): Support %#s as an alias
> for %b, in order to open doors to future repurposing of %b to
> binary output while still allowing access to its old behavior.
> * doc/coreutils.texi (printf invocation): Document it.
> * NEWS: Likewise.
> * tests/printf/printf-quote.sh: Add unit test coverage.

Patch looks good thanks.
I'd add in the attached test addition.

As for compat, I notice that existing coreutils will reject %#s,
while bash 5.2.15, ksh 1.0.4, dash 0.5.12 will treat as %s.

cheers,
Pádraig

diff --git a/tests/printf/printf.sh b/tests/printf/printf.sh
index 834012cc5..0c0948c6c 100755
--- a/tests/printf/printf.sh
+++ b/tests/printf/printf.sh
@@ -64,6 +64,8 @@ $prog '6 \41\n' | tr '\41' '!' >> out
 # prints a NUL byte followed by the digit '2' and a 'y'.
 $prog '7 \2y \02y \002y \0002y\n' |tr '\0\2' '*=' >> out
 
+$prog '8 %#s %#s %#s %#s\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out
+# Deprecated %b equivalent
 $prog '8 %b %b %b %b\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out
 
 $prog '9 %*dx\n' -2 0 >>out || fail=1
@@ -90,6 +92,7 @@ cat <<\EOF > exp
 6 !
 7 =y =y =y *2y
 8 =y =y =y =y
+8 =y =y =y =y
 9 0 x
 10 0x
 11  x