[PATCH 1/3] vsprintf: add support for printing raw buffers as hex (%*ph)

Sascha Hauer sha at pengutronix.de
Mon Dec 13 23:27:47 PST 2021


On Tue, Dec 14, 2021 at 07:57:01AM +0100, Ahmad Fatoum wrote:
> On 13.12.21 23:28, Sascha Hauer wrote:
> > On Thu, Dec 09, 2021 at 11:57:06AM +0100, Ahmad Fatoum wrote:
> >> Import from Linux support for printing buffers as a hex string
> >> with a certain separator. For larger buffers consider using
> >> print_hex_dump(). Examples:
> >>
> >>   %*ph	00 01 02  ...  3f
> >>   %*phC	00:01:02: ... :3f
> >>   %*phD	00-01-02- ... -3f
> >>   %*phN	000102 ... 3f
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> >> ---
> >>  lib/Kconfig    |  3 +++
> >>  lib/vsprintf.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >>  2 files changed, 53 insertions(+)
> >>
> >> diff --git a/lib/Kconfig b/lib/Kconfig
> >> index 718033e56e64..27e7bea6852f 100644
> >> --- a/lib/Kconfig
> >> +++ b/lib/Kconfig
> >> @@ -166,6 +166,9 @@ config PRINTF_UUID
> >>  config PRINTF_WCHAR
> >>  	bool
> >>  
> >> +config PRINTF_HEXSTR
> >> +	bool
> > 
> > So hexdumps are silently ignored when this option is disabled. Not sure
> > if this should really be configurable, but I think when it is
> > configurable it should be default y to avoid surprises.
> 
> It will be printed as a raw pointer when the option is disabled.
> There's no code in-tree that uses this format specifier yet,
> so I prefer to not make this the default and increase binary size.

Ok for now, but we should revise it once this actually gets used.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list