grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Support * as field width or precision in printf


From: Josh Triplett
Subject: [PATCH] Support * as field width or precision in printf
Date: Fri, 22 Apr 2011 14:46:02 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

The attached patch implements support for * as the field width or
precision in printf, which obtains that field width or precision from
the next va_arg. This proves particularly useful as a modifier on %s:
%.*s allows printing a non-NUL-terminated string with a known length.

Tested with the following test cases, all of which worked:

grub_printf("|%*s|\n", -50, "left-aligned in 50");
grub_printf("|%*s|\n", 50, "right-aligned in 50");
grub_printf("|%.*s|\n", 5, "truncated");
grub_printf("|%.*s|\n", -5, "truncated");
grub_printf("|%*.*s|\n", 20, 5, "truncated");
grub_printf("|%*.*s|\n", -20, 5, "truncated");
grub_printf("|%50s|\n", "hardcoded 50");
grub_printf("|%-50s|\n", "hardcoded -50");
grub_printf("|%.5s|\n", "truncated");

ChangeLog entry:

2011-04-21  Josh Triplett  <address@hidden>
2011-04-21  Burt Triplett  <address@hidden>

        * grub-core/kern/misc.c (grub_vsnprintf_real): Add support for '*'
        as field width or precision.


In bug 33144, phcoder requested justification for the inclusion of this
feature in grub's printf.  We added this feature to support our port of
ACPICA that runs as a GRUB module.  ACPICA depends on having that
particular feature in printf; it uses %*s extensively.  Now that we've
added this feature, we can also use it to simplify many other pieces of
code we've written.

Also, I just checked, and this patch adds a grand total of 8 bytes to
kernel.img.  If it helps, I've also attached a second patch to current
GRUB, which tweaks the printf implementation to save 72 bytes by
factoring out common code paths.  Given that, could we please have 8 of
those bytes? :)

- Josh Triplett

Attachment: grub-printf-star.patch
Description: Text Data

Attachment: grub-microoptimize-printf-to-save-72-bytes.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]