X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBasePrintLib%2FPrintLib.c;h=43b2b3c1d3c0c3bb71da4b239e58d46a45cabcea;hb=063bcff758e9d078dcaa6acfd2476a97176393ea;hp=13cdbe2d4b14ff00ee31b418508745bae6f22422;hpb=ebd04fc2e526ddc76f17e05cb50798fbf448e52e;p=mirror_edk2.git diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c index 13cdbe2d4b..43b2b3c1d3 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -1,12 +1,12 @@ /** @file Base Print Library instance implementation. - Copyright (c) 2006 - 2008, Intel Corporation
- Portions Copyright (c) 2008-2009 Apple Inc.
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+ Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + http://opensource.org/licenses/bsd-license.php. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -52,7 +52,7 @@ VA_LIST gNullVaList; @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. @return The number of Unicode characters in the produced output buffer not including the @@ -100,7 +100,7 @@ UnicodeVSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. @return The number of Unicode characters in the produced output buffer not including the @@ -147,7 +147,7 @@ UnicodeBSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param ... Variable argument list whose contents are accessed based on the format string specified by FormatString. @@ -165,9 +165,12 @@ UnicodeSPrint ( ) { VA_LIST Marker; + UINTN NumberOfPrinted; VA_START (Marker, FormatString); - return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); + NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); + VA_END (Marker); + return NumberOfPrinted; } /** @@ -196,7 +199,7 @@ UnicodeSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. @return The number of Unicode characters in the produced output buffer not including the @@ -242,7 +245,7 @@ UnicodeVSPrintAsciiFormat ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. @return The number of Unicode characters in the produced output buffer not including the @@ -288,7 +291,7 @@ UnicodeBSPrintAsciiFormat ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param ... Variable argument list whose contents are accessed based on the format string specified by FormatString. @@ -306,9 +309,12 @@ UnicodeSPrintAsciiFormat ( ) { VA_LIST Marker; + UINTN NumberOfPrinted; VA_START (Marker, FormatString); - return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); + NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); + VA_END (Marker); + return NumberOfPrinted; } /** @@ -328,21 +334,21 @@ UnicodeSPrintAsciiFormat ( If Width is 0, PREFIX_ZERO is ignored in Flags. If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas are inserted every 3rd digit starting from the right. - If HEX_RADIX is set in Flags, then the output buffer will be + If RADIX_HEX is set in Flags, then the output buffer will be formatted in hexadecimal format. - If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'. + If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'. If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer is padded with '0' characters so the combination of the optional '-' sign character, '0' characters, digit characters for Value, and the Null-terminator add up to Width characters. - If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT(). + If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT(). If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If unsupported bits are set in Flags, then ASSERT(). - If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT(). + If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT(). If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT() - @param Buffer Pointer to the output buffer for the produced Null-terminated + @param Buffer The pointer to the output buffer for the produced Null-terminated Unicode string. @param Flags The bitmask of flags that specify left justification, zero pad, and commas. @param Value The 64-bit signed value to convert to a string. @@ -390,7 +396,7 @@ UnicodeValueToString ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. @return The number of ASCII characters in the produced output buffer not including the @@ -434,7 +440,7 @@ AsciiVSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. @return The number of ASCII characters in the produced output buffer not including the @@ -478,7 +484,7 @@ AsciiBSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param ... Variable argument list whose contents are accessed based on the format string specified by FormatString. @@ -496,9 +502,12 @@ AsciiSPrint ( ) { VA_LIST Marker; + UINTN NumberOfPrinted; VA_START (Marker, FormatString); - return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); + NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); + VA_END (Marker); + return NumberOfPrinted; } /** @@ -527,7 +536,7 @@ AsciiSPrint ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. @return The number of ASCII characters in the produced output buffer not including the @@ -573,7 +582,7 @@ AsciiVSPrintUnicodeFormat ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. @return The number of ASCII characters in the produced output buffer not including the @@ -619,7 +628,7 @@ AsciiBSPrintUnicodeFormat ( @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param ... Variable argument list whose contents are accessed based on the format string specified by FormatString. @@ -637,9 +646,12 @@ AsciiSPrintUnicodeFormat ( ) { VA_LIST Marker; + UINTN NumberOfPrinted; VA_START (Marker, FormatString); - return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); + NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); + VA_END (Marker); + return NumberOfPrinted; } @@ -660,9 +672,9 @@ AsciiSPrintUnicodeFormat ( If Width is 0, PREFIX_ZERO is ignored in Flags. If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas are inserted every 3rd digit starting from the right. - If HEX_RADIX is set in Flags, then the output buffer will be + If RADIX_HEX is set in Flags, then the output buffer will be formatted in hexadecimal format. - If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'. + If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'. If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer is padded with '0' characters so the combination of the optional '-' sign character, '0' characters, digit characters for Value, and the Null-terminator @@ -670,10 +682,10 @@ AsciiSPrintUnicodeFormat ( If Buffer is NULL, then ASSERT(). If unsupported bits are set in Flags, then ASSERT(). - If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT(). + If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT(). If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT() - @param Buffer Pointer to the output buffer for the produced Null-terminated + @param Buffer The pointer to the output buffer for the produced Null-terminated ASCII string. @param Flags The bitmask of flags that specify left justification, zero pad, and commas. @param Value The 64-bit signed value to convert to a string. @@ -694,3 +706,51 @@ AsciiValueToString ( { return BasePrintLibConvertValueToString (Buffer, Flags, Value, Width, 1); } + +/** + Returns the number of characters that would be produced by if the formatted + output were produced not including the Null-terminator. + + If FormatString is NULL, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + @param[in] FormatString A Null-terminated Unicode format string. + @param[in] Marker VA_LIST marker for the variable argument list. + + @return The number of characters that would be produced, not including the + Null-terminator. +**/ +UINTN +EFIAPI +SPrintLength ( + IN CONST CHAR16 *FormatString, + IN VA_LIST Marker + ) +{ + ASSERT(FormatString != NULL); + ASSERT_UNICODE_BUFFER (FormatString); + return BasePrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); +} + +/** + Returns the number of characters that would be produced by if the formatted + output were produced not including the Null-terminator. + + If FormatString is NULL, then ASSERT(). + + @param[in] FormatString A Null-terminated ASCII format string. + @param[in] Marker VA_LIST marker for the variable argument list. + + @return The number of characters that would be produced, not including the + Null-terminator. +**/ +UINTN +EFIAPI +SPrintLengthAsciiFormat ( + IN CONST CHAR8 *FormatString, + IN VA_LIST Marker + ) +{ + ASSERT(FormatString != NULL); + return BasePrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); +}