]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePrintLib/PrintLib.c
af771652e4b0aebd616973ba1089ae5bc2b6f0c0
2 Base Print Library instance implementation.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "PrintLibInternal.h"
13 // Declare a VA_LIST global variable that is used in calls to BasePrintLibSPrintMarker()
14 // when the BASE_LIST parameter is valid and the VA_LIST parameter is ignored.
15 // A NULL VA_LIST can not be passed into BasePrintLibSPrintMarker() because some
16 // compilers define VA_LIST to be a structure.
20 #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)
23 Produces a Null-terminated Unicode string in an output buffer based on
24 a Null-terminated Unicode format string and a VA_LIST argument list.
26 This function is similar as vsnprintf_s defined in C11.
28 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
30 The Unicode string is produced by parsing the format string specified by FormatString.
31 Arguments are pulled from the variable argument list specified by Marker based on the
32 contents of the format string.
33 The number of Unicode characters in the produced output buffer is returned not including
36 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
37 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
39 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
40 unmodified and 0 is returned.
41 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
42 unmodified and 0 is returned.
43 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
44 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
45 buffer is unmodified and 0 is returned.
46 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
47 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
48 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
50 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
52 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
54 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
55 @param FormatString A Null-terminated Unicode format string.
56 @param Marker VA_LIST marker for the variable argument list.
58 @return The number of Unicode characters in the produced output buffer not including the
65 OUT CHAR16
*StartOfBuffer
,
67 IN CONST CHAR16
*FormatString
,
71 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
72 ASSERT_UNICODE_BUFFER (FormatString
);
73 return BasePrintLibSPrintMarker ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, FORMAT_UNICODE
| OUTPUT_UNICODE
, (CHAR8
*)FormatString
, Marker
, NULL
);
77 Produces a Null-terminated Unicode string in an output buffer based on
78 a Null-terminated Unicode format string and a BASE_LIST argument list.
80 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
82 The Unicode string is produced by parsing the format string specified by FormatString.
83 Arguments are pulled from the variable argument list specified by Marker based on the
84 contents of the format string.
85 The number of Unicode characters in the produced output buffer is returned not including
88 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
89 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
91 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
92 unmodified and 0 is returned.
93 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
94 unmodified and 0 is returned.
95 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
96 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
97 buffer is unmodified and 0 is returned.
98 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
99 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
100 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
102 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
104 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
106 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
107 @param FormatString A Null-terminated Unicode format string.
108 @param Marker BASE_LIST marker for the variable argument list.
110 @return The number of Unicode characters in the produced output buffer not including the
117 OUT CHAR16
*StartOfBuffer
,
119 IN CONST CHAR16
*FormatString
,
123 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
124 ASSERT_UNICODE_BUFFER (FormatString
);
125 return BasePrintLibSPrintMarker ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, FORMAT_UNICODE
| OUTPUT_UNICODE
, (CHAR8
*)FormatString
, gNullVaList
, Marker
);
129 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
130 Unicode format string and variable argument list.
132 This function is similar as snprintf_s defined in C11.
134 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
136 The Unicode string is produced by parsing the format string specified by FormatString.
137 Arguments are pulled from the variable argument list based on the contents of the format string.
138 The number of Unicode characters in the produced output buffer is returned not including
141 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
142 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
144 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
145 unmodified and 0 is returned.
146 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
147 unmodified and 0 is returned.
148 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
149 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
150 buffer is unmodified and 0 is returned.
151 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
152 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
153 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
155 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
157 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
159 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
160 @param FormatString A Null-terminated Unicode format string.
161 @param ... Variable argument list whose contents are accessed based on the
162 format string specified by FormatString.
164 @return The number of Unicode characters in the produced output buffer not including the
171 OUT CHAR16
*StartOfBuffer
,
173 IN CONST CHAR16
*FormatString
,
178 UINTN NumberOfPrinted
;
180 VA_START (Marker
, FormatString
);
181 NumberOfPrinted
= UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
183 return NumberOfPrinted
;
187 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
188 ASCII format string and a VA_LIST argument list.
190 This function is similar as vsnprintf_s defined in C11.
192 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
194 The Unicode string is produced by parsing the format string specified by FormatString.
195 Arguments are pulled from the variable argument list specified by Marker based on the
196 contents of the format string.
197 The number of Unicode characters in the produced output buffer is returned not including
200 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
202 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
203 unmodified and 0 is returned.
204 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
205 unmodified and 0 is returned.
206 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
207 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
208 buffer is unmodified and 0 is returned.
209 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
210 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
211 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
213 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
215 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
217 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
218 @param FormatString A Null-terminated ASCII format string.
219 @param Marker VA_LIST marker for the variable argument list.
221 @return The number of Unicode characters in the produced output buffer not including the
227 UnicodeVSPrintAsciiFormat (
228 OUT CHAR16
*StartOfBuffer
,
230 IN CONST CHAR8
*FormatString
,
234 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
235 return BasePrintLibSPrintMarker ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
, FormatString
, Marker
, NULL
);
239 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
240 ASCII format string and a BASE_LIST argument list.
242 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
244 The Unicode string is produced by parsing the format string specified by FormatString.
245 Arguments are pulled from the variable argument list specified by Marker based on the
246 contents of the format string.
247 The number of Unicode characters in the produced output buffer is returned not including
250 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
252 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
253 unmodified and 0 is returned.
254 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
255 unmodified and 0 is returned.
256 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
257 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
258 buffer is unmodified and 0 is returned.
259 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
260 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
261 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
263 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
265 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
267 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
268 @param FormatString A Null-terminated ASCII format string.
269 @param Marker BASE_LIST marker for the variable argument list.
271 @return The number of Unicode characters in the produced output buffer not including the
277 UnicodeBSPrintAsciiFormat (
278 OUT CHAR16
*StartOfBuffer
,
280 IN CONST CHAR8
*FormatString
,
284 ASSERT_UNICODE_BUFFER (StartOfBuffer
);
285 return BasePrintLibSPrintMarker ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
, FormatString
, gNullVaList
, Marker
);
289 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
290 ASCII format string and variable argument list.
292 This function is similar as snprintf_s defined in C11.
294 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
296 The Unicode string is produced by parsing the format string specified by FormatString.
297 Arguments are pulled from the variable argument list based on the contents of the
299 The number of Unicode characters in the produced output buffer is returned not including
302 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
304 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
305 unmodified and 0 is returned.
306 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
307 unmodified and 0 is returned.
308 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
309 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
310 buffer is unmodified and 0 is returned.
311 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
312 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
313 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
315 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
317 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
319 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
320 @param FormatString A Null-terminated ASCII format string.
321 @param ... Variable argument list whose contents are accessed based on the
322 format string specified by FormatString.
324 @return The number of Unicode characters in the produced output buffer not including the
330 UnicodeSPrintAsciiFormat (
331 OUT CHAR16
*StartOfBuffer
,
333 IN CONST CHAR8
*FormatString
,
338 UINTN NumberOfPrinted
;
340 VA_START (Marker
, FormatString
);
341 NumberOfPrinted
= UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
343 return NumberOfPrinted
;
346 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
349 [ATTENTION] This function is deprecated for security reason.
351 Converts a decimal value to a Null-terminated Unicode string.
353 Converts the decimal number specified by Value to a Null-terminated Unicode
354 string specified by Buffer containing at most Width characters. No padding of spaces
355 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
356 The number of Unicode characters in Buffer is returned not including the Null-terminator.
357 If the conversion contains more than Width characters, then only the first
358 Width characters are returned, and the total number of characters
359 required to perform the conversion is returned.
360 Additional conversion parameters are specified in Flags.
362 The Flags bit LEFT_JUSTIFY is always ignored.
363 All conversions are left justified in Buffer.
364 If Width is 0, PREFIX_ZERO is ignored in Flags.
365 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
366 are inserted every 3rd digit starting from the right.
367 If RADIX_HEX is set in Flags, then the output buffer will be
368 formatted in hexadecimal format.
369 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
370 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
371 then Buffer is padded with '0' characters so the combination of the optional '-'
372 sign character, '0' characters, digit characters for Value, and the Null-terminator
373 add up to Width characters.
374 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
375 If Buffer is NULL, then ASSERT().
376 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
377 If unsupported bits are set in Flags, then ASSERT().
378 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
379 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
381 @param Buffer The pointer to the output buffer for the produced Null-terminated
383 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
384 @param Value The 64-bit signed value to convert to a string.
385 @param Width The maximum number of Unicode characters to place in Buffer, not including
388 @return The number of Unicode characters in Buffer not including the Null-terminator.
393 UnicodeValueToString (
394 IN OUT CHAR16
*Buffer
,
400 ASSERT_UNICODE_BUFFER(Buffer
);
401 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
407 Converts a decimal value to a Null-terminated Unicode string.
409 Converts the decimal number specified by Value to a Null-terminated Unicode
410 string specified by Buffer containing at most Width characters. No padding of
411 spaces is ever performed. If Width is 0 then a width of
412 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
413 Width characters, then only the first Width characters are placed in Buffer.
414 Additional conversion parameters are specified in Flags.
416 The Flags bit LEFT_JUSTIFY is always ignored.
417 All conversions are left justified in Buffer.
418 If Width is 0, PREFIX_ZERO is ignored in Flags.
419 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
420 commas are inserted every 3rd digit starting from the right.
421 If RADIX_HEX is set in Flags, then the output buffer will be formatted in
423 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
425 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
426 Buffer is padded with '0' characters so the combination of the optional '-'
427 sign character, '0' characters, digit characters for Value, and the
428 Null-terminator add up to Width characters.
430 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
431 If an error would be returned, then the function will also ASSERT().
433 @param Buffer The pointer to the output buffer for the produced
434 Null-terminated Unicode string.
435 @param BufferSize The size of Buffer in bytes, including the
437 @param Flags The bitmask of flags that specify left justification,
438 zero pad, and commas.
439 @param Value The 64-bit signed value to convert to a string.
440 @param Width The maximum number of Unicode characters to place in
441 Buffer, not including the Null-terminator.
443 @retval RETURN_SUCCESS The decimal value is converted.
444 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted
446 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
447 If PcdMaximumUnicodeStringLength is not
448 zero, and BufferSize is greater than
449 (PcdMaximumUnicodeStringLength *
450 sizeof (CHAR16) + 1).
451 If unsupported bits are set in Flags.
452 If both COMMA_TYPE and RADIX_HEX are set in
454 If Width >= MAXIMUM_VALUE_CHARACTERS.
459 UnicodeValueToStringS (
460 IN OUT CHAR16
*Buffer
,
467 ASSERT_UNICODE_BUFFER(Buffer
);
468 return BasePrintLibConvertValueToStringS ((CHAR8
*)Buffer
, BufferSize
, Flags
, Value
, Width
, 2);
472 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
473 ASCII format string and a VA_LIST argument list.
475 This function is similar as vsnprintf_s defined in C11.
477 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
479 The ASCII string is produced by parsing the format string specified by FormatString.
480 Arguments are pulled from the variable argument list specified by Marker based on
481 the contents of the format string.
482 The number of ASCII characters in the produced output buffer is returned not including
485 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
486 unmodified and 0 is returned.
487 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
488 unmodified and 0 is returned.
489 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
490 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
491 is unmodified and 0 is returned.
492 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
493 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
494 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
496 If BufferSize is 0, then no output buffer is produced and 0 is returned.
498 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
500 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
501 @param FormatString A Null-terminated ASCII format string.
502 @param Marker VA_LIST marker for the variable argument list.
504 @return The number of ASCII characters in the produced output buffer not including the
511 OUT CHAR8
*StartOfBuffer
,
513 IN CONST CHAR8
*FormatString
,
517 return BasePrintLibSPrintMarker (StartOfBuffer
, BufferSize
, 0, FormatString
, Marker
, NULL
);
521 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
522 ASCII format string and a BASE_LIST argument list.
524 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
526 The ASCII string is produced by parsing the format string specified by FormatString.
527 Arguments are pulled from the variable argument list specified by Marker based on
528 the contents of the format string.
529 The number of ASCII characters in the produced output buffer is returned not including
532 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
533 unmodified and 0 is returned.
534 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
535 unmodified and 0 is returned.
536 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
537 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
538 is unmodified and 0 is returned.
539 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
540 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
541 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
543 If BufferSize is 0, then no output buffer is produced and 0 is returned.
545 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
547 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
548 @param FormatString A Null-terminated ASCII format string.
549 @param Marker BASE_LIST marker for the variable argument list.
551 @return The number of ASCII characters in the produced output buffer not including the
558 OUT CHAR8
*StartOfBuffer
,
560 IN CONST CHAR8
*FormatString
,
564 return BasePrintLibSPrintMarker (StartOfBuffer
, BufferSize
, 0, FormatString
, gNullVaList
, Marker
);
568 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
569 ASCII format string and variable argument list.
571 This function is similar as snprintf_s defined in C11.
573 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
575 The ASCII string is produced by parsing the format string specified by FormatString.
576 Arguments are pulled from the variable argument list based on the contents of the
578 The number of ASCII characters in the produced output buffer is returned not including
581 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
582 unmodified and 0 is returned.
583 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
584 unmodified and 0 is returned.
585 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
586 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
587 is unmodified and 0 is returned.
588 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
589 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
590 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
592 If BufferSize is 0, then no output buffer is produced and 0 is returned.
594 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
596 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
597 @param FormatString A Null-terminated ASCII format string.
598 @param ... Variable argument list whose contents are accessed based on the
599 format string specified by FormatString.
601 @return The number of ASCII characters in the produced output buffer not including the
608 OUT CHAR8
*StartOfBuffer
,
610 IN CONST CHAR8
*FormatString
,
615 UINTN NumberOfPrinted
;
617 VA_START (Marker
, FormatString
);
618 NumberOfPrinted
= AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
620 return NumberOfPrinted
;
624 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
625 Unicode format string and a VA_LIST argument list.
627 This function is similar as vsnprintf_s defined in C11.
629 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
631 The ASCII string is produced by parsing the format string specified by FormatString.
632 Arguments are pulled from the variable argument list specified by Marker based on
633 the contents of the format string.
634 The number of ASCII characters in the produced output buffer is returned not including
637 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
639 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
640 unmodified and 0 is returned.
641 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
642 unmodified and 0 is returned.
643 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
644 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
645 is unmodified and 0 is returned.
646 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
647 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
648 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
650 If BufferSize is 0, then no output buffer is produced and 0 is returned.
652 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
654 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
655 @param FormatString A Null-terminated Unicode format string.
656 @param Marker VA_LIST marker for the variable argument list.
658 @return The number of ASCII characters in the produced output buffer not including the
664 AsciiVSPrintUnicodeFormat (
665 OUT CHAR8
*StartOfBuffer
,
667 IN CONST CHAR16
*FormatString
,
671 ASSERT_UNICODE_BUFFER (FormatString
);
672 return BasePrintLibSPrintMarker (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, Marker
, NULL
);
676 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
677 Unicode format string and a BASE_LIST argument list.
679 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
681 The ASCII string is produced by parsing the format string specified by FormatString.
682 Arguments are pulled from the variable argument list specified by Marker based on
683 the contents of the format string.
684 The number of ASCII characters in the produced output buffer is returned not including
687 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
689 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
690 unmodified and 0 is returned.
691 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
692 unmodified and 0 is returned.
693 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
694 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
695 is unmodified and 0 is returned.
696 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
697 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
698 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
700 If BufferSize is 0, then no output buffer is produced and 0 is returned.
702 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
704 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
705 @param FormatString A Null-terminated Unicode format string.
706 @param Marker BASE_LIST marker for the variable argument list.
708 @return The number of ASCII characters in the produced output buffer not including the
714 AsciiBSPrintUnicodeFormat (
715 OUT CHAR8
*StartOfBuffer
,
717 IN CONST CHAR16
*FormatString
,
721 ASSERT_UNICODE_BUFFER (FormatString
);
722 return BasePrintLibSPrintMarker (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, gNullVaList
, Marker
);
726 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
727 Unicode format string and variable argument list.
729 This function is similar as snprintf_s defined in C11.
731 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
733 The ASCII string is produced by parsing the format string specified by FormatString.
734 Arguments are pulled from the variable argument list based on the contents of the
736 The number of ASCII characters in the produced output buffer is returned not including
739 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
741 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
742 unmodified and 0 is returned.
743 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
744 unmodified and 0 is returned.
745 If PcdMaximumAsciiStringLength is not zero, and BufferSize >
746 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
747 is unmodified and 0 is returned.
748 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
749 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
750 ASSERT(). Also, the output buffer is unmodified and 0 is returned.
752 If BufferSize is 0, then no output buffer is produced and 0 is returned.
754 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
756 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
757 @param FormatString A Null-terminated Unicode format string.
758 @param ... Variable argument list whose contents are accessed based on the
759 format string specified by FormatString.
761 @return The number of ASCII characters in the produced output buffer not including the
767 AsciiSPrintUnicodeFormat (
768 OUT CHAR8
*StartOfBuffer
,
770 IN CONST CHAR16
*FormatString
,
775 UINTN NumberOfPrinted
;
777 VA_START (Marker
, FormatString
);
778 NumberOfPrinted
= AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
780 return NumberOfPrinted
;
784 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
787 [ATTENTION] This function is deprecated for security reason.
789 Converts a decimal value to a Null-terminated ASCII string.
791 Converts the decimal number specified by Value to a Null-terminated ASCII string
792 specified by Buffer containing at most Width characters. No padding of spaces
794 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
795 The number of ASCII characters in Buffer is returned not including the Null-terminator.
796 If the conversion contains more than Width characters, then only the first Width
797 characters are returned, and the total number of characters required to perform
798 the conversion is returned.
799 Additional conversion parameters are specified in Flags.
800 The Flags bit LEFT_JUSTIFY is always ignored.
801 All conversions are left justified in Buffer.
802 If Width is 0, PREFIX_ZERO is ignored in Flags.
803 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
804 are inserted every 3rd digit starting from the right.
805 If RADIX_HEX is set in Flags, then the output buffer will be
806 formatted in hexadecimal format.
807 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
808 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
809 then Buffer is padded with '0' characters so the combination of the optional '-'
810 sign character, '0' characters, digit characters for Value, and the Null-terminator
811 add up to Width characters.
813 If Buffer is NULL, then ASSERT().
814 If unsupported bits are set in Flags, then ASSERT().
815 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
816 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
818 @param Buffer The pointer to the output buffer for the produced Null-terminated
820 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
821 @param Value The 64-bit signed value to convert to a string.
822 @param Width The maximum number of ASCII characters to place in Buffer, not including
825 @return The number of ASCII characters in Buffer not including the Null-terminator.
837 return BasePrintLibConvertValueToString (Buffer
, Flags
, Value
, Width
, 1);
843 Converts a decimal value to a Null-terminated Ascii string.
845 Converts the decimal number specified by Value to a Null-terminated Ascii
846 string specified by Buffer containing at most Width characters. No padding of
847 spaces is ever performed. If Width is 0 then a width of
848 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
849 Width characters, then only the first Width characters are placed in Buffer.
850 Additional conversion parameters are specified in Flags.
852 The Flags bit LEFT_JUSTIFY is always ignored.
853 All conversions are left justified in Buffer.
854 If Width is 0, PREFIX_ZERO is ignored in Flags.
855 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
856 commas are inserted every 3rd digit starting from the right.
857 If RADIX_HEX is set in Flags, then the output buffer will be formatted in
859 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
861 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
862 Buffer is padded with '0' characters so the combination of the optional '-'
863 sign character, '0' characters, digit characters for Value, and the
864 Null-terminator add up to Width characters.
866 If an error would be returned, then the function will ASSERT().
868 @param Buffer The pointer to the output buffer for the produced
869 Null-terminated Ascii string.
870 @param BufferSize The size of Buffer in bytes, including the
872 @param Flags The bitmask of flags that specify left justification,
873 zero pad, and commas.
874 @param Value The 64-bit signed value to convert to a string.
875 @param Width The maximum number of Ascii characters to place in
876 Buffer, not including the Null-terminator.
878 @retval RETURN_SUCCESS The decimal value is converted.
879 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted
881 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
882 If PcdMaximumAsciiStringLength is not
883 zero, and BufferSize is greater than
884 PcdMaximumAsciiStringLength.
885 If unsupported bits are set in Flags.
886 If both COMMA_TYPE and RADIX_HEX are set in
888 If Width >= MAXIMUM_VALUE_CHARACTERS.
893 AsciiValueToStringS (
894 IN OUT CHAR8
*Buffer
,
901 return BasePrintLibConvertValueToStringS (Buffer
, BufferSize
, Flags
, Value
, Width
, 1);
905 Returns the number of characters that would be produced by if the formatted
906 output were produced not including the Null-terminator.
908 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
910 If FormatString is NULL, then ASSERT() and 0 is returned.
911 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more
912 than PcdMaximumUnicodeStringLength Unicode characters not including the
913 Null-terminator, then ASSERT() and 0 is returned.
915 @param[in] FormatString A Null-terminated Unicode format string.
916 @param[in] Marker VA_LIST marker for the variable argument list.
918 @return The number of characters that would be produced, not including the
924 IN CONST CHAR16
*FormatString
,
928 ASSERT_UNICODE_BUFFER (FormatString
);
929 return BasePrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
933 Returns the number of characters that would be produced by if the formatted
934 output were produced not including the Null-terminator.
936 If FormatString is NULL, then ASSERT() and 0 is returned.
937 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more
938 than PcdMaximumAsciiStringLength Ascii characters not including the
939 Null-terminator, then ASSERT() and 0 is returned.
941 @param[in] FormatString A Null-terminated ASCII format string.
942 @param[in] Marker VA_LIST marker for the variable argument list.
944 @return The number of characters that would be produced, not including the
949 SPrintLengthAsciiFormat (
950 IN CONST CHAR8
*FormatString
,
954 return BasePrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);