[PATCH] MdePkg/BasePrintLib: Add %z specifier


Pedro Falcato
 

%z is used in standard C99 as the printf specifier for size_t types.
Add support for it so we can portably print UINTN.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Signed-off-by: Pedro Falcato <pedro.falcato@...>
---
MdePkg/Library/BasePrintLib/PrintLibInternal.c | 9 +++++++++
MdePkg/Library/BasePrintLib/PrintLibInternal.h | 1 +
2 files changed, 10 insertions(+)

diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
index 42b598a432..1cd99b2213 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
@@ -720,6 +720,9 @@ BasePrintLibSPrintMarker (
case 'l':
Flags |= LONG_TYPE;
break;
+ case 'z':
+ Flags |= SIZET_TYPE;
+ break;
case '*':
if ((Flags & PRECISION) == 0) {
Flags |= PAD_TO_WIDTH;
@@ -833,6 +836,12 @@ BasePrintLibSPrintMarker (
} else {
Value = BASE_ARG (BaseListMarker, int);
}
+ } else if ((Flags & SIZET_TYPE) != 0) {
+ if (BaseListMarker == NULL) {
+ Value = VA_ARG (VaListMarker, UINTN);
+ } else {
+ Value = BASE_ARG (BaseListMarker, UINTN);
+ }
} else {
if (BaseListMarker == NULL) {
Value = VA_ARG (VaListMarker, INT64);
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
index 34d591c6fc..9193e6192b 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
@@ -29,6 +29,7 @@
#define ARGUMENT_REVERSED BIT12
#define COUNT_ONLY_NO_PRINT BIT13
#define UNSIGNED_TYPE BIT14
+#define SIZET_TYPE BIT15

//
// Record date and time information
--
2.37.0

Join devel@edk2.groups.io to automatically receive all group messages.