]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BasePrintLib: Add safe print functions [A|U]ValueToStringS
authorHao Wu <hao.a.wu@intel.com>
Fri, 23 Dec 2016 06:34:26 +0000 (14:34 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 21 Feb 2017 05:56:14 +0000 (13:56 +0800)
Add the following 2 APIs:
UnicodeValueToStringS
AsciiValueToStringS

These safe version APIs are used to enhance their counterpart (APIs
without trailing 'S' in function names).

They perform checks to the input parameters and will return relative
status to reflect the check result.

Return RETURN_INVALID_PARAMETER when:
1). The input Buffer is NULL.
2). The input BufferSize is greater than (PcdMaximumUnicodeStringLength *
sizeof (CHAR16) + 1) for UnicodeValueToStringS or greater than
PcdMaximumAsciiStringLength for AsciiValueToStringS.
3). The input Flags is not set properly.
4). The input Width is not smaller than MAXIMUM_VALUE_CHARACTERS.

Return RETURN_BUFFER_TOO_SMALL when:
1). The input BufferSize cannot hold the converted value.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Include/Library/PrintLib.h
MdePkg/Library/BasePrintLib/PrintLib.c
MdePkg/Library/BasePrintLib/PrintLibInternal.c
MdePkg/Library/BasePrintLib/PrintLibInternal.h

index 5f663239b7bc9b90e5a7a3812fd6d63298fb60b2..8c11dab696353021863e9b5a26c0818ba1359bef 100644 (file)
@@ -541,6 +541,67 @@ UnicodeValueToString (
   IN UINTN       Width\r
   );\r
 \r
+/**\r
+  Converts a decimal value to a Null-terminated Unicode string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Unicode\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Unicode string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of Unicode characters to place in\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   (PcdMaximumUnicodeStringLength *\r
+                                   sizeof (CHAR16) + 1).\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+UnicodeValueToStringS (\r
+  IN OUT CHAR16  *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  );\r
+\r
 /**\r
   Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
   ASCII format string and a VA_LIST argument list.\r
@@ -870,6 +931,66 @@ AsciiValueToString (
   IN  UINTN      Width\r
   );\r
 \r
+/**\r
+  Converts a decimal value to a Null-terminated Ascii string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Ascii\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Ascii string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of Ascii characters to place in\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   PcdMaximumAsciiStringLength.\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiValueToStringS (\r
+  IN OUT CHAR8   *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  );\r
+\r
 /**\r
   Returns the number of characters that would be produced by if the formatted \r
   output were produced not including the Null-terminator.\r
index bf8c7bfe123a8b438182262813d5ee6499dbabd3..221b52e23cf21dc96035641b0967020fa3ceb351 100644 (file)
@@ -403,6 +403,71 @@ UnicodeValueToString (
   return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);\r
 }\r
 \r
+/**\r
+  Converts a decimal value to a Null-terminated Unicode string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Unicode\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Unicode string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of Unicode characters to place in\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   (PcdMaximumUnicodeStringLength *\r
+                                   sizeof (CHAR16) + 1).\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+UnicodeValueToStringS (\r
+  IN OUT CHAR16  *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  )\r
+{\r
+  ASSERT_UNICODE_BUFFER(Buffer);\r
+  return BasePrintLibConvertValueToStringS ((CHAR8 *)Buffer, BufferSize, Flags, Value, Width, 2);\r
+}\r
+\r
 /**\r
   Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
   ASCII format string and a VA_LIST argument list.\r
@@ -768,6 +833,69 @@ AsciiValueToString (
   return BasePrintLibConvertValueToString (Buffer, Flags, Value, Width, 1);\r
 }\r
 \r
+/**\r
+  Converts a decimal value to a Null-terminated Ascii string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Ascii\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Ascii string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of Ascii characters to place in\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   PcdMaximumAsciiStringLength.\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiValueToStringS (\r
+  IN OUT CHAR8   *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  )\r
+{\r
+  return BasePrintLibConvertValueToStringS (Buffer, BufferSize, Flags, Value, Width, 1);\r
+}\r
+\r
 /**\r
   Returns the number of characters that would be produced by if the formatted \r
   output were produced not including the Null-terminator.\r
index 155fe6a461a9dcdee26c2329613e9504ac2c4298..9b15a07ac066378750bde3af31b0b6872611c824 100644 (file)
@@ -291,6 +291,210 @@ BasePrintLibConvertValueToString (
   return ((Buffer - OriginalBuffer) / Increment);\r
 }\r
 \r
+/**\r
+  Internal function that converts a decimal value to a Null-terminated string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated string\r
+  specified by Buffer containing at most Width characters. If Width is 0 then a\r
+  width of MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more\r
+  than Width characters, then only the first Width characters are placed in\r
+  Buffer. Additional conversion parameters are specified in Flags.\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If Value is < 0, then the fist character in Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,\r
+  then Buffer is padded with '0' characters so the combination of the optional\r
+  '-' sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If an error would be returned, the function will ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of characters to place in Buffer,\r
+                      not including the Null-terminator.\r
+  @param  Increment   The character increment in Buffer.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If Increment is 1 and\r
+                                   PcdMaximumAsciiStringLength is not zero,\r
+                                   BufferSize is greater than\r
+                                   PcdMaximumAsciiStringLength.\r
+                                   If Increment is not 1 and\r
+                                   PcdMaximumUnicodeStringLength is not zero,\r
+                                   BufferSize is greater than\r
+                                   (PcdMaximumUnicodeStringLength *\r
+                                   sizeof (CHAR16) + 1).\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+BasePrintLibConvertValueToStringS (\r
+  IN OUT CHAR8   *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width,\r
+  IN UINTN       Increment\r
+  )\r
+{\r
+  CHAR8  *EndBuffer;\r
+  CHAR8  ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
+  CHAR8  *ValueBufferPtr;\r
+  UINTN  Count;\r
+  UINTN  Digits;\r
+  UINTN  Index;\r
+  UINTN  Radix;\r
+\r
+  //\r
+  // 1. Buffer shall not be a null pointer.\r
+  //\r
+  SAFE_PRINT_CONSTRAINT_CHECK ((Buffer != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. BufferSize shall not be greater than (RSIZE_MAX * sizeof (CHAR16)) for\r
+  //    Unicode output string or shall not be greater than ASCII_RSIZE_MAX for\r
+  //    Ascii output string.\r
+  //\r
+  if (Increment == 1) {\r
+    //\r
+    // Ascii output string\r
+    //\r
+    if (ASCII_RSIZE_MAX != 0) {\r
+      SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= ASCII_RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+    }\r
+  } else {\r
+    //\r
+    // Unicode output string\r
+    //\r
+    if (RSIZE_MAX != 0) {\r
+      SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= RSIZE_MAX * sizeof (CHAR16) + 1), RETURN_INVALID_PARAMETER);\r
+    }\r
+  }\r
+\r
+  //\r
+  // 3. Flags shall be set properly.\r
+  //\r
+  SAFE_PRINT_CONSTRAINT_CHECK (((Flags & ~(LEFT_JUSTIFY | COMMA_TYPE | PREFIX_ZERO | RADIX_HEX)) == 0), RETURN_INVALID_PARAMETER);\r
+  SAFE_PRINT_CONSTRAINT_CHECK ((((Flags & COMMA_TYPE) == 0) || ((Flags & RADIX_HEX) == 0)), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 4. Width shall be smaller than MAXIMUM_VALUE_CHARACTERS.\r
+  //\r
+  SAFE_PRINT_CONSTRAINT_CHECK ((Width < MAXIMUM_VALUE_CHARACTERS), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // Width is 0 or COMMA_TYPE is set, PREFIX_ZERO is ignored.\r
+  //\r
+  if (Width == 0 || (Flags & COMMA_TYPE) != 0) {\r
+    Flags &= ~((UINTN) PREFIX_ZERO);\r
+  }\r
+  //\r
+  // If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
+  //\r
+  if (Width == 0) {\r
+    Width = MAXIMUM_VALUE_CHARACTERS - 1;\r
+  }\r
+\r
+  //\r
+  // Count the characters of the output string.\r
+  //\r
+  Count = 0;\r
+  Radix = ((Flags & RADIX_HEX) == 0)? 10 : 16;\r
+\r
+  if ((Flags & PREFIX_ZERO) != 0) {\r
+    Count = Width;\r
+  } else {\r
+    if ((Value < 0) && ((Flags & RADIX_HEX) == 0)) {\r
+      Count++;  // minus sign\r
+      ValueBufferPtr = BasePrintLibValueToString (ValueBuffer, -Value, Radix);\r
+    } else {\r
+      ValueBufferPtr = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
+    }\r
+    Digits = ValueBufferPtr - ValueBuffer;\r
+    Count += Digits;\r
+\r
+    if ((Flags & COMMA_TYPE) != 0) {\r
+      Count += (Digits - 1) / 3;  // commas\r
+    }\r
+  }\r
+\r
+  Width = MIN (Count, Width);\r
+\r
+  //\r
+  // 5. BufferSize shall be large enough to hold the converted string.\r
+  //\r
+  SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize >= (Width + 1) * Increment), RETURN_BUFFER_TOO_SMALL);\r
+\r
+  //\r
+  // Set the tag for the end of the input Buffer.\r
+  //\r
+  EndBuffer = Buffer + Width * Increment;\r
+\r
+  //\r
+  // Convert decimal negative\r
+  //\r
+  if ((Value < 0) && ((Flags & RADIX_HEX) == 0)) {\r
+    Value = -Value;\r
+    Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, '-', Increment);\r
+    Width--;\r
+  }\r
+\r
+  //\r
+  // Count the length of the value string.\r
+  //\r
+  ValueBufferPtr = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
+  Count = ValueBufferPtr - ValueBuffer;\r
+\r
+  //\r
+  // Append Zero\r
+  //\r
+  if ((Flags & PREFIX_ZERO) != 0) {\r
+    Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Count, '0', Increment);\r
+  }\r
+\r
+  //\r
+  // Print Comma type for every 3 characters\r
+  //\r
+  Digits = Count % 3;\r
+  if (Digits != 0) {\r
+    Digits = 3 - Digits;\r
+  }\r
+  for (Index = 0; Index < Count; Index++) {\r
+    Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, *ValueBufferPtr--, Increment);\r
+    if ((Flags & COMMA_TYPE) != 0) {\r
+      Digits++;\r
+      if (Digits == 3) {\r
+        Digits = 0;\r
+        if ((Index + 1) < Count) {\r
+          Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', Increment);\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Print Null-terminator\r
+  //\r
+  BasePrintLibFillBuffer (Buffer, EndBuffer + Increment, 1, 0, Increment);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
 /**\r
   Worker function that produces a Null-terminated string in an output buffer \r
   based on a Null-terminated format string and a VA_LIST argument list.\r
index fccef9b9b9671d0cae79ba2e195d66055f06f87e..052e699574c646c6d3b1d97406de90f4a0fb22e4 100644 (file)
@@ -213,4 +213,65 @@ BasePrintLibConvertValueToString (
   IN UINTN       Increment\r
   );\r
 \r
+/**\r
+  Internal function that converts a decimal value to a Null-terminated string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated string\r
+  specified by Buffer containing at most Width characters. If Width is 0 then a\r
+  width of MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more\r
+  than Width characters, then only the first Width characters are placed in\r
+  Buffer. Additional conversion parameters are specified in Flags.\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If Value is < 0, then the fist character in Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,\r
+  then Buffer is padded with '0' characters so the combination of the optional\r
+  '-' sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If an error would be returned, the function will ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero pad, and commas.\r
+  @param  Value       The 64-bit signed value to convert to a string.\r
+  @param  Width       The maximum number of characters to place in Buffer,\r
+                      not including the Null-terminator.\r
+  @param  Increment   The character increment in Buffer.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If Increment is 1 and\r
+                                   PcdMaximumAsciiStringLength is not zero,\r
+                                   BufferSize is greater than\r
+                                   PcdMaximumAsciiStringLength.\r
+                                   If Increment is not 1 and\r
+                                   PcdMaximumUnicodeStringLength is not zero,\r
+                                   BufferSize is greater than\r
+                                   (PcdMaximumUnicodeStringLength *\r
+                                   sizeof (CHAR16) + 1).\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+RETURN_STATUS\r
+BasePrintLibConvertValueToStringS (\r
+  IN OUT CHAR8   *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width,\r
+  IN UINTN       Increment\r
+  );\r
+\r
 #endif\r