2 Instance of Print Library based on gEfiPrint2SProtocolGuid.
4 Implement the print library instance by wrap the interface
5 provided in the Print2S protocol. This protocol is defined as the internal
6 protocol related to this implementation, not in the public spec. So, this
7 library instance is only for this code base.
9 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Protocol/Print2.h>
18 #include <Library/PrintLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PcdLib.h>
24 #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)
29 #define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength))
30 #define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength))
32 #define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \
34 ASSERT (Expression); \
35 if (!(Expression)) { \
40 EFI_PRINT2S_PROTOCOL
*mPrint2SProtocol
= NULL
;
43 The constructor function caches the pointer to Print2S protocol.
45 The constructor function locates Print2S protocol from protocol database.
46 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
48 @param ImageHandle The firmware allocated handle for the EFI image.
49 @param SystemTable A pointer to the EFI System Table.
51 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
57 IN EFI_HANDLE ImageHandle
,
58 IN EFI_SYSTEM_TABLE
*SystemTable
63 Status
= SystemTable
->BootServices
->LocateProtocol (
64 &gEfiPrint2SProtocolGuid
,
66 (VOID
**) &mPrint2SProtocol
68 ASSERT_EFI_ERROR (Status
);
69 ASSERT (mPrint2SProtocol
!= NULL
);
76 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated
79 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.
80 @param Format Null-terminated format string.
81 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.
82 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.
83 @param Size The size, in bytes, of the BaseListMarker buffer.
85 @return TRUE The VA_LIST has been converted to BASE_LIST.
86 @return FALSE The VA_LIST has not been converted to BASE_LIST.
90 DxePrintLibPrint2ProtocolVaListToBaseList (
91 IN BOOLEAN AsciiFormat
,
92 IN CONST CHAR8
*Format
,
93 IN VA_LIST VaListMarker
,
94 OUT BASE_LIST BaseListMarker
,
98 BASE_LIST BaseListStart
;
99 UINTN BytesPerFormatCharacter
;
101 UINTN FormatCharacter
;
105 ASSERT (BaseListMarker
!= NULL
);
106 SAFE_PRINT_CONSTRAINT_CHECK ((Format
!= NULL
), FALSE
);
108 BaseListStart
= BaseListMarker
;
111 if (ASCII_RSIZE_MAX
!= 0) {
112 SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format
, ASCII_RSIZE_MAX
+ 1) <= ASCII_RSIZE_MAX
), FALSE
);
114 BytesPerFormatCharacter
= 1;
117 if (RSIZE_MAX
!= 0) {
118 SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16
*)Format
, RSIZE_MAX
+ 1) <= RSIZE_MAX
), FALSE
);
120 BytesPerFormatCharacter
= 2;
125 // Get the first character from the format string
127 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
129 while (FormatCharacter
!= 0) {
130 if (FormatCharacter
== '%') {
134 // Parse Flags and Width
136 for (Done
= FALSE
; !Done
; ) {
138 // Get the next character from the format string
140 Format
+= BytesPerFormatCharacter
;
143 // Get the next character from the format string
145 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
147 switch (FormatCharacter
) {
169 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
173 // Make no output if Format string terminates unexpectedly when
174 // looking up for flag, width, precision and type.
176 Format
-= BytesPerFormatCharacter
;
178 // break skipped on purpose.
187 // Handle each argument type
189 switch (FormatCharacter
) {
191 if (sizeof (VOID
*) > 4) {
199 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
201 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
209 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
212 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
215 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
221 // If BASE_LIST is larger than Size, then return FALSE
223 if (((UINTN
)BaseListMarker
- (UINTN
)BaseListStart
) > Size
) {
224 DEBUG ((DEBUG_ERROR
, "The input variable argument list is too long. Please consider breaking into multiple print calls.\n"));
229 // Get the next character from the format string
231 Format
+= BytesPerFormatCharacter
;
234 // Get the next character from the format string
236 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
242 Produces a Null-terminated Unicode string in an output buffer based on
243 a Null-terminated Unicode format string and a VA_LIST argument list.
245 This function is similar as vsnprintf_s defined in C11.
247 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
249 The Unicode string is produced by parsing the format string specified by FormatString.
250 Arguments are pulled from the variable argument list specified by Marker based on the
251 contents of the format string.
252 The number of Unicode characters in the produced output buffer is returned not including
255 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
256 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
258 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
259 unmodified and 0 is returned.
260 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
261 unmodified and 0 is returned.
262 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
263 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
264 buffer is unmodified and 0 is returned.
265 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
266 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
267 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
269 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
271 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
273 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
274 @param FormatString A Null-terminated Unicode format string.
275 @param Marker VA_LIST marker for the variable argument list.
277 @return The number of Unicode characters in the produced output buffer not including the
284 OUT CHAR16
*StartOfBuffer
,
286 IN CONST CHAR16
*FormatString
,
290 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
293 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
294 ASSERT_UNICODE_BUFFER (FormatString
);
296 Converted
= DxePrintLibPrint2ProtocolVaListToBaseList (
298 (CHAR8
*)FormatString
,
300 (BASE_LIST
)BaseListMarker
,
301 sizeof (BaseListMarker
) - 8
307 return UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
311 Produces a Null-terminated Unicode string in an output buffer based on
312 a Null-terminated Unicode format string and a BASE_LIST argument list.
314 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
316 The Unicode string is produced by parsing the format string specified by FormatString.
317 Arguments are pulled from the variable argument list specified by Marker based on the
318 contents of the format string.
319 The number of Unicode characters in the produced output buffer is returned not including
322 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
323 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
325 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
326 unmodified and 0 is returned.
327 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
328 unmodified and 0 is returned.
329 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
330 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
331 buffer is unmodified and 0 is returned.
332 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
333 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
334 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
336 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
338 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
340 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
341 @param FormatString A Null-terminated Unicode format string.
342 @param Marker BASE_LIST marker for the variable argument list.
344 @return The number of Unicode characters in the produced output buffer not including the
351 OUT CHAR16
*StartOfBuffer
,
353 IN CONST CHAR16
*FormatString
,
357 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
358 ASSERT_UNICODE_BUFFER (FormatString
);
359 return mPrint2SProtocol
->UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
363 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
364 Unicode format string and variable argument list.
366 This function is similar as snprintf_s defined in C11.
368 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
370 The Unicode string is produced by parsing the format string specified by FormatString.
371 Arguments are pulled from the variable argument list based on the contents of the format string.
372 The number of Unicode characters in the produced output buffer is returned not including
375 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
376 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
378 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
379 unmodified and 0 is returned.
380 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
381 unmodified and 0 is returned.
382 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
383 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
384 buffer is unmodified and 0 is returned.
385 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
386 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
387 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
389 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
391 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
393 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
394 @param FormatString A Null-terminated Unicode format string.
395 @param ... Variable argument list whose contents are accessed based on the
396 format string specified by FormatString.
398 @return The number of Unicode characters in the produced output buffer not including the
405 OUT CHAR16
*StartOfBuffer
,
407 IN CONST CHAR16
*FormatString
,
412 UINTN NumberOfPrinted
;
414 VA_START (Marker
, FormatString
);
415 NumberOfPrinted
= UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
417 return NumberOfPrinted
;
421 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
422 ASCII format string and a VA_LIST argument list.
424 This function is similar as vsnprintf_s defined in C11.
426 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
428 The Unicode string is produced by parsing the format string specified by FormatString.
429 Arguments are pulled from the variable argument list specified by Marker based on the
430 contents of the format string.
431 The number of Unicode characters in the produced output buffer is returned not including
434 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
436 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
437 unmodified and 0 is returned.
438 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
439 unmodified and 0 is returned.
440 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
441 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
442 buffer is unmodified and 0 is returned.
443 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
444 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
445 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
447 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
449 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
451 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
452 @param FormatString A Null-terminated ASCII format string.
453 @param Marker VA_LIST marker for the variable argument list.
455 @return The number of Unicode characters in the produced output buffer not including the
461 UnicodeVSPrintAsciiFormat (
462 OUT CHAR16
*StartOfBuffer
,
464 IN CONST CHAR8
*FormatString
,
468 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
471 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
473 Converted
= DxePrintLibPrint2ProtocolVaListToBaseList (
477 (BASE_LIST
)BaseListMarker
,
478 sizeof (BaseListMarker
) - 8
484 return UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
488 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
489 ASCII format string and a BASE_LIST argument list.
491 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
493 The Unicode string is produced by parsing the format string specified by FormatString.
494 Arguments are pulled from the variable argument list specified by Marker based on the
495 contents of the format string.
496 The number of Unicode characters in the produced output buffer is returned not including
499 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
501 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
502 unmodified and 0 is returned.
503 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
504 unmodified and 0 is returned.
505 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
506 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
507 buffer is unmodified and 0 is returned.
508 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
509 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
510 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
512 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
514 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
516 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
517 @param FormatString A Null-terminated ASCII format string.
518 @param Marker BASE_LIST marker for the variable argument list.
520 @return The number of Unicode characters in the produced output buffer not including the
526 UnicodeBSPrintAsciiFormat (
527 OUT CHAR16
*StartOfBuffer
,
529 IN CONST CHAR8
*FormatString
,
533 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
534 return mPrint2SProtocol
->UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
538 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
539 ASCII format string and variable argument list.
541 This function is similar as snprintf_s defined in C11.
543 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
545 The Unicode string is produced by parsing the format string specified by FormatString.
546 Arguments are pulled from the variable argument list based on the contents of the
548 The number of Unicode characters in the produced output buffer is returned not including
551 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
553 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
554 unmodified and 0 is returned.
555 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
556 unmodified and 0 is returned.
557 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
558 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
559 buffer is unmodified and 0 is returned.
560 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
561 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
562 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
564 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
566 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
568 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
569 @param FormatString A Null-terminated ASCII format string.
570 @param ... Variable argument list whose contents are accessed based on the
571 format string specified by FormatString.
573 @return The number of Unicode characters in the produced output buffer not including the
579 UnicodeSPrintAsciiFormat (
580 OUT CHAR16
*StartOfBuffer
,
582 IN CONST CHAR8
*FormatString
,
587 UINTN NumberOfPrinted
;
589 VA_START (Marker
, FormatString
);
590 NumberOfPrinted
= UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
592 return NumberOfPrinted
;
595 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
598 [ATTENTION] This function is deprecated for security reason.
600 Converts a decimal value to a Null-terminated Unicode string.
602 Converts the decimal number specified by Value to a Null-terminated Unicode
603 string specified by Buffer containing at most Width characters. No padding of spaces
604 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
605 The number of Unicode characters in Buffer is returned not including the Null-terminator.
606 If the conversion contains more than Width characters, then only the first
607 Width characters are returned, and the total number of characters
608 required to perform the conversion is returned.
609 Additional conversion parameters are specified in Flags.
611 The Flags bit LEFT_JUSTIFY is always ignored.
612 All conversions are left justified in Buffer.
613 If Width is 0, PREFIX_ZERO is ignored in Flags.
614 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
615 are inserted every 3rd digit starting from the right.
616 If RADIX_HEX is set in Flags, then the output buffer will be
617 formatted in hexadecimal format.
618 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
619 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
620 then Buffer is padded with '0' characters so the combination of the optional '-'
621 sign character, '0' characters, digit characters for Value, and the Null-terminator
622 add up to Width characters.
623 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
624 If Buffer is NULL, then ASSERT().
625 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
626 If unsupported bits are set in Flags, then ASSERT().
627 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
628 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
630 @param Buffer Pointer to the output buffer for the produced Null-terminated
632 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
633 @param Value The 64-bit signed value to convert to a string.
634 @param Width The maximum number of Unicode characters to place in Buffer, not including
637 @return The number of Unicode characters in Buffer not including the Null-terminator.
642 UnicodeValueToString (
643 IN OUT CHAR16
*Buffer
,
649 RETURN_STATUS Status
;
653 BufferSize
= (MAXIMUM_VALUE_CHARACTERS
+ 1) * sizeof (CHAR16
);
655 BufferSize
= (Width
+ 1) * sizeof (CHAR16
);
658 Status
= mPrint2SProtocol
->UnicodeValueToStringS (Buffer
, BufferSize
, Flags
, Value
, Width
);
659 if (RETURN_ERROR (Status
)) {
663 return StrnLenS (Buffer
, BufferSize
/ sizeof (CHAR16
));
669 Converts a decimal value to a Null-terminated Unicode string.
671 Converts the decimal number specified by Value to a Null-terminated Unicode
672 string specified by Buffer containing at most Width characters. No padding of
673 spaces is ever performed. If Width is 0 then a width of
674 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
675 Width characters, then only the first Width characters are placed in Buffer.
676 Additional conversion parameters are specified in Flags.
678 The Flags bit LEFT_JUSTIFY is always ignored.
679 All conversions are left justified in Buffer.
680 If Width is 0, PREFIX_ZERO is ignored in Flags.
681 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
682 commas are inserted every 3rd digit starting from the right.
683 If RADIX_HEX is set in Flags, then the output buffer will be formatted in
685 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
687 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
688 Buffer is padded with '0' characters so the combination of the optional '-'
689 sign character, '0' characters, digit characters for Value, and the
690 Null-terminator add up to Width characters.
692 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
693 If an error would be returned, then the function will also ASSERT().
695 @param Buffer The pointer to the output buffer for the produced
696 Null-terminated Unicode string.
697 @param BufferSize The size of Buffer in bytes, including the
699 @param Flags The bitmask of flags that specify left justification,
700 zero pad, and commas.
701 @param Value The 64-bit signed value to convert to a string.
702 @param Width The maximum number of Unicode characters to place in
703 Buffer, not including the Null-terminator.
705 @retval RETURN_SUCCESS The decimal value is converted.
706 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted
708 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
709 If PcdMaximumUnicodeStringLength is not
710 zero, and BufferSize is greater than
711 (PcdMaximumUnicodeStringLength *
712 sizeof (CHAR16) + 1).
713 If unsupported bits are set in Flags.
714 If both COMMA_TYPE and RADIX_HEX are set in
716 If Width >= MAXIMUM_VALUE_CHARACTERS.
721 UnicodeValueToStringS (
722 IN OUT CHAR16
*Buffer
,
729 return mPrint2SProtocol
->UnicodeValueToStringS (Buffer
, BufferSize
, Flags
, Value
, Width
);
733 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
734 ASCII format string and a VA_LIST argument list.
736 This function is similar as vsnprintf_s defined in C11.
738 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
740 The ASCII string is produced by parsing the format string specified by FormatString.
741 Arguments are pulled from the variable argument list specified by Marker based on
742 the contents of the format string.
743 The number of ASCII characters in the produced output buffer is returned not including
746 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
747 unmodified and 0 is returned.
748 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
749 unmodified and 0 is returned.
750 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
751 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
752 is unmodified and 0 is returned.
753 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
754 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
755 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
757 If BufferSize is 0, then no output buffer is produced and 0 is returned.
759 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
761 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
762 @param FormatString A Null-terminated ASCII format string.
763 @param Marker VA_LIST marker for the variable argument list.
765 @return The number of ASCII characters in the produced output buffer not including the
772 OUT CHAR8
*StartOfBuffer
,
774 IN CONST CHAR8
*FormatString
,
778 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
781 Converted
= DxePrintLibPrint2ProtocolVaListToBaseList (
785 (BASE_LIST
)BaseListMarker
,
786 sizeof (BaseListMarker
) - 8
792 return AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
796 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
797 ASCII format string and a BASE_LIST argument list.
799 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
801 The ASCII string is produced by parsing the format string specified by FormatString.
802 Arguments are pulled from the variable argument list specified by Marker based on
803 the contents of the format string.
804 The number of ASCII characters in the produced output buffer is returned not including
807 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
808 unmodified and 0 is returned.
809 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
810 unmodified and 0 is returned.
811 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
812 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
813 is unmodified and 0 is returned.
814 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
815 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
816 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
818 If BufferSize is 0, then no output buffer is produced and 0 is returned.
820 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
822 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
823 @param FormatString A Null-terminated ASCII format string.
824 @param Marker BASE_LIST marker for the variable argument list.
826 @return The number of ASCII characters in the produced output buffer not including the
833 OUT CHAR8
*StartOfBuffer
,
835 IN CONST CHAR8
*FormatString
,
839 return mPrint2SProtocol
->AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
843 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
844 ASCII format string and variable argument list.
846 This function is similar as snprintf_s defined in C11.
848 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
850 The ASCII string is produced by parsing the format string specified by FormatString.
851 Arguments are pulled from the variable argument list based on the contents of the
853 The number of ASCII characters in the produced output buffer is returned not including
856 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
857 unmodified and 0 is returned.
858 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
859 unmodified and 0 is returned.
860 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
861 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
862 is unmodified and 0 is returned.
863 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
864 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
865 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
867 If BufferSize is 0, then no output buffer is produced and 0 is returned.
869 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
871 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
872 @param FormatString A Null-terminated ASCII format string.
873 @param ... Variable argument list whose contents are accessed based on the
874 format string specified by FormatString.
876 @return The number of ASCII characters in the produced output buffer not including the
883 OUT CHAR8
*StartOfBuffer
,
885 IN CONST CHAR8
*FormatString
,
890 UINTN NumberOfPrinted
;
892 VA_START (Marker
, FormatString
);
893 NumberOfPrinted
= AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
895 return NumberOfPrinted
;
899 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
900 Unicode format string and a VA_LIST argument list.
902 This function is similar as vsnprintf_s defined in C11.
904 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
906 The ASCII string is produced by parsing the format string specified by FormatString.
907 Arguments are pulled from the variable argument list specified by Marker based on
908 the contents of the format string.
909 The number of ASCII characters in the produced output buffer is returned not including
912 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
914 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
915 unmodified and 0 is returned.
916 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
917 unmodified and 0 is returned.
918 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
919 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
920 is unmodified and 0 is returned.
921 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
922 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
923 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
925 If BufferSize is 0, then no output buffer is produced and 0 is returned.
927 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
929 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
930 @param FormatString A Null-terminated Unicode format string.
931 @param Marker VA_LIST marker for the variable argument list.
933 @return The number of ASCII characters in the produced output buffer not including the
939 AsciiVSPrintUnicodeFormat (
940 OUT CHAR8
*StartOfBuffer
,
942 IN CONST CHAR16
*FormatString
,
946 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
949 ASSERT_UNICODE_BUFFER (FormatString
);
951 Converted
= DxePrintLibPrint2ProtocolVaListToBaseList (
953 (CHAR8
*)FormatString
,
955 (BASE_LIST
)BaseListMarker
,
956 sizeof (BaseListMarker
) - 8
962 return AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
966 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
967 Unicode format string and a BASE_LIST argument list.
969 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
971 The ASCII string is produced by parsing the format string specified by FormatString.
972 Arguments are pulled from the variable argument list specified by Marker based on
973 the contents of the format string.
974 The number of ASCII characters in the produced output buffer is returned not including
977 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
979 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
980 unmodified and 0 is returned.
981 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
982 unmodified and 0 is returned.
983 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
984 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
985 is unmodified and 0 is returned.
986 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
987 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
988 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
990 If BufferSize is 0, then no output buffer is produced and 0 is returned.
992 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
994 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
995 @param FormatString A Null-terminated Unicode format string.
996 @param Marker BASE_LIST marker for the variable argument list.
998 @return The number of ASCII characters in the produced output buffer not including the
1004 AsciiBSPrintUnicodeFormat (
1005 OUT CHAR8
*StartOfBuffer
,
1006 IN UINTN BufferSize
,
1007 IN CONST CHAR16
*FormatString
,
1011 ASSERT_UNICODE_BUFFER (FormatString
);
1012 return mPrint2SProtocol
->AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
1016 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
1017 Unicode format string and variable argument list.
1019 This function is similar as snprintf_s defined in C11.
1021 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
1023 The ASCII string is produced by parsing the format string specified by FormatString.
1024 Arguments are pulled from the variable argument list based on the contents of the
1026 The number of ASCII characters in the produced output buffer is returned not including
1027 the Null-terminator.
1029 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1031 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
1032 unmodified and 0 is returned.
1033 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
1034 unmodified and 0 is returned.
1035 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
1036 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
1037 is unmodified and 0 is returned.
1038 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
1039 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
1040 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
1042 If BufferSize is 0, then no output buffer is produced and 0 is returned.
1044 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
1046 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
1047 @param FormatString A Null-terminated Unicode format string.
1048 @param ... Variable argument list whose contents are accessed based on the
1049 format string specified by FormatString.
1051 @return The number of ASCII characters in the produced output buffer not including the
1057 AsciiSPrintUnicodeFormat (
1058 OUT CHAR8
*StartOfBuffer
,
1059 IN UINTN BufferSize
,
1060 IN CONST CHAR16
*FormatString
,
1065 UINTN NumberOfPrinted
;
1067 VA_START (Marker
, FormatString
);
1068 NumberOfPrinted
= AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
1070 return NumberOfPrinted
;
1074 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1077 [ATTENTION] This function is deprecated for security reason.
1079 Converts a decimal value to a Null-terminated ASCII string.
1081 Converts the decimal number specified by Value to a Null-terminated ASCII string
1082 specified by Buffer containing at most Width characters. No padding of spaces
1084 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1085 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1086 If the conversion contains more than Width characters, then only the first Width
1087 characters are returned, and the total number of characters required to perform
1088 the conversion is returned.
1089 Additional conversion parameters are specified in Flags.
1090 The Flags bit LEFT_JUSTIFY is always ignored.
1091 All conversions are left justified in Buffer.
1092 If Width is 0, PREFIX_ZERO is ignored in Flags.
1093 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1094 are inserted every 3rd digit starting from the right.
1095 If RADIX_HEX is set in Flags, then the output buffer will be
1096 formatted in hexadecimal format.
1097 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
1098 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
1099 then Buffer is padded with '0' characters so the combination of the optional '-'
1100 sign character, '0' characters, digit characters for Value, and the Null-terminator
1101 add up to Width characters.
1103 If Buffer is NULL, then ASSERT().
1104 If unsupported bits are set in Flags, then ASSERT().
1105 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
1106 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1108 @param Buffer Pointer to the output buffer for the produced Null-terminated
1110 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1111 @param Value The 64-bit signed value to convert to a string.
1112 @param Width The maximum number of ASCII characters to place in Buffer, not including
1113 the Null-terminator.
1115 @return The number of ASCII characters in Buffer not including the Null-terminator.
1120 AsciiValueToString (
1127 RETURN_STATUS Status
;
1131 BufferSize
= (MAXIMUM_VALUE_CHARACTERS
+ 1) * sizeof (CHAR8
);
1133 BufferSize
= (Width
+ 1) * sizeof (CHAR8
);
1136 Status
= mPrint2SProtocol
->AsciiValueToStringS (Buffer
, BufferSize
, Flags
, Value
, Width
);
1137 if (RETURN_ERROR (Status
)) {
1141 return AsciiStrnLenS (Buffer
, BufferSize
/ sizeof (CHAR8
));
1147 Converts a decimal value to a Null-terminated Ascii string.
1149 Converts the decimal number specified by Value to a Null-terminated Ascii
1150 string specified by Buffer containing at most Width characters. No padding of
1151 spaces is ever performed. If Width is 0 then a width of
1152 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
1153 Width characters, then only the first Width characters are placed in Buffer.
1154 Additional conversion parameters are specified in Flags.
1156 The Flags bit LEFT_JUSTIFY is always ignored.
1157 All conversions are left justified in Buffer.
1158 If Width is 0, PREFIX_ZERO is ignored in Flags.
1159 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
1160 commas are inserted every 3rd digit starting from the right.
1161 If RADIX_HEX is set in Flags, then the output buffer will be formatted in
1163 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
1165 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
1166 Buffer is padded with '0' characters so the combination of the optional '-'
1167 sign character, '0' characters, digit characters for Value, and the
1168 Null-terminator add up to Width characters.
1170 If an error would be returned, then the function will ASSERT().
1172 @param Buffer The pointer to the output buffer for the produced
1173 Null-terminated Ascii string.
1174 @param BufferSize The size of Buffer in bytes, including the
1176 @param Flags The bitmask of flags that specify left justification,
1177 zero pad, and commas.
1178 @param Value The 64-bit signed value to convert to a string.
1179 @param Width The maximum number of Ascii characters to place in
1180 Buffer, not including the Null-terminator.
1182 @retval RETURN_SUCCESS The decimal value is converted.
1183 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted
1185 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
1186 If PcdMaximumAsciiStringLength is not
1187 zero, and BufferSize is greater than
1188 PcdMaximumAsciiStringLength.
1189 If unsupported bits are set in Flags.
1190 If both COMMA_TYPE and RADIX_HEX are set in
1192 If Width >= MAXIMUM_VALUE_CHARACTERS.
1197 AsciiValueToStringS (
1198 IN OUT CHAR8
*Buffer
,
1199 IN UINTN BufferSize
,
1205 return mPrint2SProtocol
->AsciiValueToStringS (Buffer
, BufferSize
, Flags
, Value
, Width
);
1208 #define PREFIX_SIGN BIT1
1209 #define PREFIX_BLANK BIT2
1210 #define LONG_TYPE BIT4
1211 #define OUTPUT_UNICODE BIT6
1212 #define FORMAT_UNICODE BIT8
1213 #define PAD_TO_WIDTH BIT9
1214 #define ARGUMENT_UNICODE BIT10
1215 #define PRECISION BIT11
1216 #define ARGUMENT_REVERSED BIT12
1217 #define COUNT_ONLY_NO_PRINT BIT13
1218 #define UNSIGNED_TYPE BIT14
1221 // Record date and time information
1237 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1240 Internal function that convert a number to a string in Buffer.
1242 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
1244 @param Buffer Location to place the ASCII string of Value.
1245 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
1246 @param Radix Radix of the value
1248 @return A pointer to the end of buffer filled with ASCII string.
1252 InternalPrintLibValueToString (
1253 IN OUT CHAR8
*Buffer
,
1261 // Loop to convert one digit at a time in reverse order
1265 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
1266 *(++Buffer
) = mHexStr
[Remainder
];
1267 } while (Value
!= 0);
1270 // Return pointer of the end of filled buffer.
1276 Worker function that produces a Null-terminated string in an output buffer
1277 based on a Null-terminated format string and a VA_LIST argument list.
1279 VSPrint function to process format and place the results in Buffer. Since a
1280 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1281 this is the main print working routine.
1283 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1285 @param[out] Buffer The character buffer to print the results of the
1286 parsing of Format into.
1287 @param[in] BufferSize The maximum number of characters to put into
1289 @param[in] Flags Initial flags value.
1290 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1291 and COUNT_ONLY_NO_PRINT set.
1292 @param[in] Format A Null-terminated format string.
1293 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1295 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1296 by processing Format.
1298 @return The number of characters printed not including the Null-terminator.
1299 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1300 modification to Buffer.
1304 InternalPrintLibSPrintMarker (
1306 IN UINTN BufferSize
,
1308 IN CONST CHAR8
*Format
,
1309 IN VA_LIST VaListMarker
, OPTIONAL
1310 IN BASE_LIST BaseListMarker OPTIONAL
1314 Worker function that produces a Null-terminated string in an output buffer
1315 based on a Null-terminated format string and variable argument list.
1317 VSPrint function to process format and place the results in Buffer. Since a
1318 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1319 this is the main print working routine
1321 @param StartOfBuffer The character buffer to print the results of the parsing
1323 @param BufferSize The maximum number of characters to put into buffer.
1324 Zero means no limit.
1325 @param Flags Initial flags value.
1326 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
1327 @param FormatString A Null-terminated format string.
1328 @param ... The variable argument list.
1330 @return The number of characters printed.
1335 InternalPrintLibSPrint (
1336 OUT CHAR8
*StartOfBuffer
,
1337 IN UINTN BufferSize
,
1339 IN CONST CHAR8
*FormatString
,
1344 UINTN NumberOfPrinted
;
1346 VA_START (Marker
, FormatString
);
1347 NumberOfPrinted
= InternalPrintLibSPrintMarker (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
, NULL
);
1349 return NumberOfPrinted
;
1352 #define WARNING_STATUS_NUMBER 5
1353 #define ERROR_STATUS_NUMBER 33
1355 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
* CONST mStatusString
[] = {
1356 "Success", // RETURN_SUCCESS = 0
1357 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
1358 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
1359 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
1360 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
1361 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5
1362 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1363 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1364 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1365 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1366 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1367 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1368 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1369 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1370 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1371 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1372 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1373 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1374 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1375 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1376 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1377 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1378 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1379 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1380 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1381 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1382 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1383 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1384 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1385 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1386 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT
1387 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT
1388 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT
1389 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT
1390 "Reserved (29)", // RESERVED = 29 | MAX_BIT
1391 "Reserved (30)", // RESERVED = 30 | MAX_BIT
1392 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT
1393 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT
1394 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT
1398 Internal function that places the character into the Buffer.
1400 Internal function that places ASCII or Unicode character into the Buffer.
1402 @param Buffer The buffer to place the Unicode or ASCII string.
1403 @param EndBuffer The end of the input Buffer. No characters will be
1405 @param Length The count of character to be placed into Buffer.
1406 (Negative value indicates no buffer fill.)
1407 @param Character The character to be placed into Buffer.
1408 @param Increment The character increment in Buffer.
1414 InternalPrintLibFillBuffer (
1416 IN CHAR8
*EndBuffer
,
1424 for (Index
= 0; Index
< Length
&& Buffer
< EndBuffer
; Index
++) {
1425 *Buffer
= (CHAR8
) Character
;
1426 if (Increment
!= 1) {
1427 *(Buffer
+ 1) = (CHAR8
)(Character
>> 8);
1429 Buffer
+= Increment
;
1436 Worker function that produces a Null-terminated string in an output buffer
1437 based on a Null-terminated format string and a VA_LIST argument list.
1439 VSPrint function to process format and place the results in Buffer. Since a
1440 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1441 this is the main print working routine.
1443 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1445 @param[out] Buffer The character buffer to print the results of the
1446 parsing of Format into.
1447 @param[in] BufferSize The maximum number of characters to put into
1449 @param[in] Flags Initial flags value.
1450 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1451 and COUNT_ONLY_NO_PRINT set.
1452 @param[in] Format A Null-terminated format string.
1453 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1455 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1456 by processing Format.
1458 @return The number of characters printed not including the Null-terminator.
1459 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1460 modification to Buffer.
1464 InternalPrintLibSPrintMarker (
1466 IN UINTN BufferSize
,
1468 IN CONST CHAR8
*Format
,
1469 IN VA_LIST VaListMarker
, OPTIONAL
1470 IN BASE_LIST BaseListMarker OPTIONAL
1473 CHAR8
*OriginalBuffer
;
1475 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1476 UINT32 BytesPerOutputCharacter
;
1477 UINTN BytesPerFormatCharacter
;
1479 UINTN FormatCharacter
;
1483 CONST CHAR8
*ArgumentString
;
1489 INTN BytesPerArgumentCharacter
;
1490 UINTN ArgumentCharacter
;
1498 RETURN_STATUS Status
;
1502 UINTN LengthToReturn
;
1505 // If you change this code be sure to match the 2 versions of this function.
1506 // Nearly identical logic is found in the BasePrintLib and
1507 // DxePrintLibPrint2Protocol (both PrintLib instances).
1511 // 1. Buffer shall not be a null pointer when both BufferSize > 0 and
1512 // COUNT_ONLY_NO_PRINT is not set in Flags.
1514 if ((BufferSize
> 0) && ((Flags
& COUNT_ONLY_NO_PRINT
) == 0)) {
1515 SAFE_PRINT_CONSTRAINT_CHECK ((Buffer
!= NULL
), 0);
1519 // 2. Format shall not be a null pointer when BufferSize > 0 or when
1520 // COUNT_ONLY_NO_PRINT is set in Flags.
1522 if ((BufferSize
> 0) || ((Flags
& COUNT_ONLY_NO_PRINT
) != 0)) {
1523 SAFE_PRINT_CONSTRAINT_CHECK ((Format
!= NULL
), 0);
1527 // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output or
1528 // ASCII_RSIZE_MAX for Ascii output.
1530 if ((Flags
& OUTPUT_UNICODE
) != 0) {
1531 if (RSIZE_MAX
!= 0) {
1532 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize
<= RSIZE_MAX
), 0);
1534 BytesPerOutputCharacter
= 2;
1536 if (ASCII_RSIZE_MAX
!= 0) {
1537 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize
<= ASCII_RSIZE_MAX
), 0);
1539 BytesPerOutputCharacter
= 1;
1543 // 4. Format shall not contain more than RSIZE_MAX Unicode characters or
1544 // ASCII_RSIZE_MAX Ascii characters.
1546 if ((Flags
& FORMAT_UNICODE
) != 0) {
1547 if (RSIZE_MAX
!= 0) {
1548 SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16
*)Format
, RSIZE_MAX
+ 1) <= RSIZE_MAX
), 0);
1550 BytesPerFormatCharacter
= 2;
1551 FormatMask
= 0xffff;
1553 if (ASCII_RSIZE_MAX
!= 0) {
1554 SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format
, ASCII_RSIZE_MAX
+ 1) <= ASCII_RSIZE_MAX
), 0);
1556 BytesPerFormatCharacter
= 1;
1560 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
1561 if (BufferSize
== 0) {
1566 // We can run without a Buffer for counting only.
1568 if (BufferSize
== 0) {
1575 OriginalBuffer
= NULL
;
1578 // Reserve space for the Null terminator.
1580 if (Buffer
!= NULL
) {
1582 OriginalBuffer
= Buffer
;
1585 // Set the tag for the end of the input Buffer.
1587 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1591 // Get the first character from the format string
1593 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1596 // Loop until the end of the format string is reached or the output buffer is full
1598 while (FormatCharacter
!= 0) {
1599 if ((Buffer
!= NULL
) && (Buffer
>= EndBuffer
)) {
1603 // Clear all the flag bits except those that may have been passed in
1605 Flags
&= (UINTN
) (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1608 // Set the default width to zero, and the default precision to 1
1618 switch (FormatCharacter
) {
1621 // Parse Flags and Width
1623 for (Done
= FALSE
; !Done
; ) {
1624 Format
+= BytesPerFormatCharacter
;
1625 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1626 switch (FormatCharacter
) {
1631 Flags
|= LEFT_JUSTIFY
;
1634 Flags
|= PREFIX_SIGN
;
1637 Flags
|= PREFIX_BLANK
;
1640 Flags
|= COMMA_TYPE
;
1647 if ((Flags
& PRECISION
) == 0) {
1648 Flags
|= PAD_TO_WIDTH
;
1649 if (BaseListMarker
== NULL
) {
1650 Width
= VA_ARG (VaListMarker
, UINTN
);
1652 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1655 if (BaseListMarker
== NULL
) {
1656 Precision
= VA_ARG (VaListMarker
, UINTN
);
1658 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1663 if ((Flags
& PRECISION
) == 0) {
1664 Flags
|= PREFIX_ZERO
;
1675 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1676 Count
= (Count
* 10) + FormatCharacter
- '0';
1677 Format
+= BytesPerFormatCharacter
;
1678 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1680 Format
-= BytesPerFormatCharacter
;
1681 if ((Flags
& PRECISION
) == 0) {
1682 Flags
|= PAD_TO_WIDTH
;
1691 // Make no output if Format string terminates unexpectedly when
1692 // looking up for flag, width, precision and type.
1694 Format
-= BytesPerFormatCharacter
;
1697 // break skipped on purpose.
1706 // Handle each argument type
1708 switch (FormatCharacter
) {
1711 // Flag space, +, 0, L & l are invalid for type p.
1713 Flags
&= ~((UINTN
) (PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
));
1714 if (sizeof (VOID
*) > 4) {
1718 // break skipped on purpose
1721 Flags
|= PREFIX_ZERO
;
1723 // break skipped on purpose
1728 // break skipped on purpose
1731 if ((Flags
& RADIX_HEX
) == 0) {
1732 Flags
&= ~((UINTN
) (PREFIX_SIGN
));
1733 Flags
|= UNSIGNED_TYPE
;
1736 // break skipped on purpose
1739 if ((Flags
& LONG_TYPE
) == 0) {
1741 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1742 // This assumption is made so the format string definition is compatible with the ANSI C
1743 // Specification for formatted strings. It is recommended that the Base Types be used
1744 // everywhere, but in this one case, compliance with ANSI C is more important, and
1745 // provides an implementation that is compatible with that largest possible set of CPU
1746 // architectures. This is why the type "int" is used in this one case.
1748 if (BaseListMarker
== NULL
) {
1749 Value
= VA_ARG (VaListMarker
, int);
1751 Value
= BASE_ARG (BaseListMarker
, int);
1754 if (BaseListMarker
== NULL
) {
1755 Value
= VA_ARG (VaListMarker
, INT64
);
1757 Value
= BASE_ARG (BaseListMarker
, INT64
);
1760 if ((Flags
& PREFIX_BLANK
) != 0) {
1763 if ((Flags
& PREFIX_SIGN
) != 0) {
1766 if ((Flags
& COMMA_TYPE
) != 0) {
1769 if ((Flags
& RADIX_HEX
) == 0) {
1772 Flags
&= ~((UINTN
) PREFIX_ZERO
);
1775 if (Value
< 0 && (Flags
& UNSIGNED_TYPE
) == 0) {
1776 Flags
|= PREFIX_SIGN
;
1779 } else if ((Flags
& UNSIGNED_TYPE
) != 0 && (Flags
& LONG_TYPE
) == 0) {
1781 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1782 // This assumption is made so the format string definition is compatible with the ANSI C
1783 // Specification for formatted strings. It is recommended that the Base Types be used
1784 // everywhere, but in this one case, compliance with ANSI C is more important, and
1785 // provides an implementation that is compatible with that largest possible set of CPU
1786 // architectures. This is why the type "unsigned int" is used in this one case.
1788 Value
= (unsigned int)Value
;
1793 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1795 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1796 // This assumption is made so the format string definition is compatible with the ANSI C
1797 // Specification for formatted strings. It is recommended that the Base Types be used
1798 // everywhere, but in this one case, compliance with ANSI C is more important, and
1799 // provides an implementation that is compatible with that largest possible set of CPU
1800 // architectures. This is why the type "unsigned int" is used in this one case.
1802 Value
= (unsigned int)Value
;
1806 // Convert Value to a reversed string
1808 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1809 if (Value
== 0 && Precision
== 0) {
1812 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1816 Digits
= 3 - Digits
;
1818 if (Comma
&& Count
!= 0) {
1819 Count
+= ((Count
- 1) / 3);
1825 Flags
|= ARGUMENT_REVERSED
;
1827 if ((Flags
& PREFIX_ZERO
) != 0) {
1828 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1829 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1830 if ((Flags
& PRECISION
) == 0) {
1840 Flags
|= ARGUMENT_UNICODE
;
1842 // break skipped on purpose
1845 if (BaseListMarker
== NULL
) {
1846 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1848 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1850 if (ArgumentString
== NULL
) {
1851 Flags
&= (~(UINTN
)ARGUMENT_UNICODE
);
1852 ArgumentString
= "<null string>";
1855 // Set the default precision for string to be zero if not specified.
1857 if ((Flags
& PRECISION
) == 0) {
1863 if (BaseListMarker
== NULL
) {
1864 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1866 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1868 ArgumentString
= (CHAR8
*)&Character
;
1869 Flags
|= ARGUMENT_UNICODE
;
1873 if (BaseListMarker
== NULL
) {
1874 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1876 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1878 if (TmpGuid
== NULL
) {
1879 ArgumentString
= "<null guid>";
1881 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1882 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1883 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1884 InternalPrintLibSPrint (
1886 MAXIMUM_VALUE_CHARACTERS
,
1888 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1901 ArgumentString
= ValueBuffer
;
1906 if (BaseListMarker
== NULL
) {
1907 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1909 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1911 if (TmpTime
== NULL
) {
1912 ArgumentString
= "<null time>";
1914 InternalPrintLibSPrint (
1916 MAXIMUM_VALUE_CHARACTERS
,
1918 "%02d/%02d/%04d %02d:%02d",
1925 ArgumentString
= ValueBuffer
;
1930 if (BaseListMarker
== NULL
) {
1931 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1933 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1935 ArgumentString
= ValueBuffer
;
1936 if (RETURN_ERROR (Status
)) {
1940 Index
= Status
& ~MAX_BIT
;
1941 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1942 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1946 if (Index
<= WARNING_STATUS_NUMBER
) {
1947 ArgumentString
= mStatusString
[Index
];
1950 if (ArgumentString
== ValueBuffer
) {
1951 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1956 Format
+= BytesPerFormatCharacter
;
1957 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1958 if (FormatCharacter
== '\n') {
1960 // Translate '\r\n' to '\r\n'
1962 ArgumentString
= "\r\n";
1965 // Translate '\r' to '\r'
1967 ArgumentString
= "\r";
1968 Format
-= BytesPerFormatCharacter
;
1974 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1976 ArgumentString
= "\r\n";
1977 Format
+= BytesPerFormatCharacter
;
1978 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1979 if (FormatCharacter
!= '\r') {
1980 Format
-= BytesPerFormatCharacter
;
1987 // if the type is '%' or unknown, then print it to the screen
1989 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1990 Flags
|= ARGUMENT_UNICODE
;
1996 Format
+= BytesPerFormatCharacter
;
1997 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
1998 if (FormatCharacter
== '\n') {
2000 // Translate '\r\n' to '\r\n'
2002 ArgumentString
= "\r\n";
2005 // Translate '\r' to '\r'
2007 ArgumentString
= "\r";
2008 Format
-= BytesPerFormatCharacter
;
2014 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
2016 ArgumentString
= "\r\n";
2017 Format
+= BytesPerFormatCharacter
;
2018 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
2019 if (FormatCharacter
!= '\r') {
2020 Format
-= BytesPerFormatCharacter
;
2025 ArgumentString
= (CHAR8
*)&FormatCharacter
;
2026 Flags
|= ARGUMENT_UNICODE
;
2031 // Retrieve the ArgumentString attriubutes
2033 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
2034 ArgumentMask
= 0xffff;
2035 BytesPerArgumentCharacter
= 2;
2037 ArgumentMask
= 0xff;
2038 BytesPerArgumentCharacter
= 1;
2040 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
2041 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
2044 // Compute the number of characters in ArgumentString and store it in Count
2045 // ArgumentString is either null-terminated, or it contains Precision characters
2048 (ArgumentString
[Count
* BytesPerArgumentCharacter
] != '\0' ||
2049 (BytesPerArgumentCharacter
> 1 &&
2050 ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]!= '\0')) &&
2051 (Count
< Precision
|| ((Flags
& PRECISION
) == 0));
2053 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
2054 if (ArgumentCharacter
== 0) {
2060 if (Precision
< Count
) {
2065 // Pad before the string
2067 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
2068 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
2069 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2070 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
2076 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
2077 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2078 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
2081 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
2082 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2083 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, '0', BytesPerOutputCharacter
);
2086 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
2087 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2088 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, ' ', BytesPerOutputCharacter
);
2091 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
2092 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2093 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
2099 // Output the Prefix character if it is present
2107 // Copy the string into the output buffer performing the required type conversions
2109 while (Index
< Count
&&
2110 (ArgumentString
[0] != '\0' ||
2111 (BytesPerArgumentCharacter
> 1 && ArgumentString
[1] != '\0'))) {
2112 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (((UINT8
)*(ArgumentString
+ 1)) << 8)) & ArgumentMask
;
2114 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
2115 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2116 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, ArgumentCharacter
, BytesPerOutputCharacter
);
2118 ArgumentString
+= BytesPerArgumentCharacter
;
2125 if (Index
< Count
) {
2126 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
2127 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2128 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, ',', BytesPerOutputCharacter
);
2136 // Pad after the string
2138 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
2139 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
2140 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
2141 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
2146 // Get the next character from the format string
2148 Format
+= BytesPerFormatCharacter
;
2151 // Get the next character from the format string
2153 FormatCharacter
= ((*Format
& 0xff) | ((BytesPerFormatCharacter
== 1) ? 0 : (*(Format
+ 1) << 8))) & FormatMask
;
2156 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
2157 return (LengthToReturn
/ BytesPerOutputCharacter
);
2160 ASSERT (Buffer
!= NULL
);
2162 // Null terminate the Unicode or ASCII string
2164 InternalPrintLibFillBuffer (Buffer
, EndBuffer
+ BytesPerOutputCharacter
, 1, 0, BytesPerOutputCharacter
);
2166 return ((Buffer
- OriginalBuffer
) / BytesPerOutputCharacter
);
2170 Returns the number of characters that would be produced by if the formatted
2171 output were produced not including the Null-terminator.
2173 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
2175 If FormatString is NULL, then ASSERT() and 0 is returned.
2176 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more
2177 than PcdMaximumUnicodeStringLength Unicode characters not including the
2178 Null-terminator, then ASSERT() and 0 is returned.
2180 @param[in] FormatString A Null-terminated Unicode format string.
2181 @param[in] Marker VA_LIST marker for the variable argument list.
2183 @return The number of characters that would be produced, not including the
2189 IN CONST CHAR16
*FormatString
,
2193 ASSERT_UNICODE_BUFFER (FormatString
);
2194 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
2198 Returns the number of characters that would be produced by if the formatted
2199 output were produced not including the Null-terminator.
2201 If FormatString is NULL, then ASSERT() and 0 is returned.
2202 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more
2203 than PcdMaximumAsciiStringLength Ascii characters not including the
2204 Null-terminator, then ASSERT() and 0 is returned.
2206 @param[in] FormatString A Null-terminated ASCII format string.
2207 @param[in] Marker VA_LIST marker for the variable argument list.
2209 @return The number of characters that would be produced, not including the
2214 SPrintLengthAsciiFormat (
2215 IN CONST CHAR8
*FormatString
,
2219 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);