]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/BasePrintLib/PrintLib.c
MdePkg/BasePrintLib: Refine the comment for AsciiValueToStringS API
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLib.c
... / ...
CommitLineData
1/** @file\r
2 Base Print Library instance implementation.\r
3\r
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "PrintLibInternal.h"\r
17\r
18//\r
19// Declare a VA_LIST global variable that is used in calls to BasePrintLibSPrintMarker()\r
20// when the BASE_LIST parameter is valid and the VA_LIST parameter is ignored. \r
21// A NULL VA_LIST can not be passed into BasePrintLibSPrintMarker() because some \r
22// compilers define VA_LIST to be a structure.\r
23//\r
24VA_LIST gNullVaList;\r
25\r
26#define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)\r
27\r
28/**\r
29 Produces a Null-terminated Unicode string in an output buffer based on\r
30 a Null-terminated Unicode format string and a VA_LIST argument list.\r
31\r
32 This function is similar as vsnprintf_s defined in C11.\r
33\r
34 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
35 and BufferSize.\r
36 The Unicode string is produced by parsing the format string specified by FormatString.\r
37 Arguments are pulled from the variable argument list specified by Marker based on the\r
38 contents of the format string.\r
39 The number of Unicode characters in the produced output buffer is returned not including\r
40 the Null-terminator.\r
41\r
42 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
43 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
44\r
45 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
46 unmodified and 0 is returned.\r
47 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
48 unmodified and 0 is returned.\r
49 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
50 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
51 buffer is unmodified and 0 is returned.\r
52 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
53 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
54 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
55\r
56 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
57\r
58 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
59 Unicode string.\r
60 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
61 @param FormatString A Null-terminated Unicode format string.\r
62 @param Marker VA_LIST marker for the variable argument list.\r
63\r
64 @return The number of Unicode characters in the produced output buffer not including the\r
65 Null-terminator.\r
66\r
67**/\r
68UINTN\r
69EFIAPI\r
70UnicodeVSPrint (\r
71 OUT CHAR16 *StartOfBuffer,\r
72 IN UINTN BufferSize,\r
73 IN CONST CHAR16 *FormatString,\r
74 IN VA_LIST Marker\r
75 )\r
76{\r
77 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
78 ASSERT_UNICODE_BUFFER (FormatString);\r
79 return BasePrintLibSPrintMarker ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker, NULL);\r
80}\r
81\r
82/**\r
83 Produces a Null-terminated Unicode string in an output buffer based on\r
84 a Null-terminated Unicode format string and a BASE_LIST argument list.\r
85\r
86 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
87 and BufferSize.\r
88 The Unicode string is produced by parsing the format string specified by FormatString.\r
89 Arguments are pulled from the variable argument list specified by Marker based on the\r
90 contents of the format string.\r
91 The number of Unicode characters in the produced output buffer is returned not including\r
92 the Null-terminator.\r
93\r
94 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
95 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
96\r
97 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
98 unmodified and 0 is returned.\r
99 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
100 unmodified and 0 is returned.\r
101 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
102 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
103 buffer is unmodified and 0 is returned.\r
104 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
105 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
106 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
107\r
108 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
109\r
110 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
111 Unicode string.\r
112 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
113 @param FormatString A Null-terminated Unicode format string.\r
114 @param Marker BASE_LIST marker for the variable argument list.\r
115\r
116 @return The number of Unicode characters in the produced output buffer not including the\r
117 Null-terminator.\r
118\r
119**/\r
120UINTN\r
121EFIAPI\r
122UnicodeBSPrint (\r
123 OUT CHAR16 *StartOfBuffer,\r
124 IN UINTN BufferSize,\r
125 IN CONST CHAR16 *FormatString,\r
126 IN BASE_LIST Marker\r
127 )\r
128{\r
129 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
130 ASSERT_UNICODE_BUFFER (FormatString);\r
131 return BasePrintLibSPrintMarker ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, gNullVaList, Marker);\r
132}\r
133\r
134/**\r
135 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
136 Unicode format string and variable argument list.\r
137\r
138 This function is similar as snprintf_s defined in C11.\r
139\r
140 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
141 and BufferSize.\r
142 The Unicode string is produced by parsing the format string specified by FormatString.\r
143 Arguments are pulled from the variable argument list based on the contents of the format string.\r
144 The number of Unicode characters in the produced output buffer is returned not including\r
145 the Null-terminator.\r
146\r
147 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
148 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
149\r
150 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
151 unmodified and 0 is returned.\r
152 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
153 unmodified and 0 is returned.\r
154 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
155 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
156 buffer is unmodified and 0 is returned.\r
157 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
158 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
159 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
160\r
161 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
162\r
163 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
164 Unicode string.\r
165 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
166 @param FormatString A Null-terminated Unicode format string.\r
167 @param ... Variable argument list whose contents are accessed based on the\r
168 format string specified by FormatString.\r
169\r
170 @return The number of Unicode characters in the produced output buffer not including the\r
171 Null-terminator.\r
172\r
173**/\r
174UINTN\r
175EFIAPI\r
176UnicodeSPrint (\r
177 OUT CHAR16 *StartOfBuffer,\r
178 IN UINTN BufferSize,\r
179 IN CONST CHAR16 *FormatString,\r
180 ...\r
181 )\r
182{\r
183 VA_LIST Marker;\r
184 UINTN NumberOfPrinted;\r
185\r
186 VA_START (Marker, FormatString);\r
187 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
188 VA_END (Marker);\r
189 return NumberOfPrinted;\r
190}\r
191\r
192/**\r
193 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
194 ASCII format string and a VA_LIST argument list.\r
195\r
196 This function is similar as vsnprintf_s defined in C11.\r
197\r
198 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
199 and BufferSize.\r
200 The Unicode string is produced by parsing the format string specified by FormatString.\r
201 Arguments are pulled from the variable argument list specified by Marker based on the\r
202 contents of the format string.\r
203 The number of Unicode characters in the produced output buffer is returned not including\r
204 the Null-terminator.\r
205\r
206 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
207\r
208 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
209 unmodified and 0 is returned.\r
210 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
211 unmodified and 0 is returned.\r
212 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
213 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
214 buffer is unmodified and 0 is returned.\r
215 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
216 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
217 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
218\r
219 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
220\r
221 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
222 Unicode string.\r
223 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
224 @param FormatString A Null-terminated ASCII format string.\r
225 @param Marker VA_LIST marker for the variable argument list.\r
226\r
227 @return The number of Unicode characters in the produced output buffer not including the\r
228 Null-terminator.\r
229\r
230**/\r
231UINTN\r
232EFIAPI\r
233UnicodeVSPrintAsciiFormat (\r
234 OUT CHAR16 *StartOfBuffer,\r
235 IN UINTN BufferSize,\r
236 IN CONST CHAR8 *FormatString,\r
237 IN VA_LIST Marker\r
238 )\r
239{\r
240 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
241 return BasePrintLibSPrintMarker ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE, FormatString, Marker, NULL);\r
242}\r
243\r
244/**\r
245 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
246 ASCII format string and a BASE_LIST argument list.\r
247\r
248 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
249 and BufferSize.\r
250 The Unicode string is produced by parsing the format string specified by FormatString.\r
251 Arguments are pulled from the variable argument list specified by Marker based on the\r
252 contents of the format string.\r
253 The number of Unicode characters in the produced output buffer is returned not including\r
254 the Null-terminator.\r
255\r
256 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
257\r
258 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
259 unmodified and 0 is returned.\r
260 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
261 unmodified and 0 is returned.\r
262 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
263 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
264 buffer is unmodified and 0 is returned.\r
265 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
266 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
267 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
268\r
269 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
270\r
271 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
272 Unicode string.\r
273 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
274 @param FormatString A Null-terminated ASCII format string.\r
275 @param Marker BASE_LIST marker for the variable argument list.\r
276\r
277 @return The number of Unicode characters in the produced output buffer not including the\r
278 Null-terminator.\r
279\r
280**/\r
281UINTN\r
282EFIAPI\r
283UnicodeBSPrintAsciiFormat (\r
284 OUT CHAR16 *StartOfBuffer,\r
285 IN UINTN BufferSize,\r
286 IN CONST CHAR8 *FormatString,\r
287 IN BASE_LIST Marker\r
288 )\r
289{\r
290 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
291 return BasePrintLibSPrintMarker ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE, FormatString, gNullVaList, Marker);\r
292}\r
293\r
294/**\r
295 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
296 ASCII format string and variable argument list.\r
297\r
298 This function is similar as snprintf_s defined in C11.\r
299\r
300 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
301 and BufferSize.\r
302 The Unicode string is produced by parsing the format string specified by FormatString.\r
303 Arguments are pulled from the variable argument list based on the contents of the\r
304 format string.\r
305 The number of Unicode characters in the produced output buffer is returned not including\r
306 the Null-terminator.\r
307\r
308 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
309\r
310 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
311 unmodified and 0 is returned.\r
312 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
313 unmodified and 0 is returned.\r
314 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
315 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
316 buffer is unmodified and 0 is returned.\r
317 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
318 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
319 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
320\r
321 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
322\r
323 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
324 Unicode string.\r
325 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
326 @param FormatString A Null-terminated ASCII format string.\r
327 @param ... Variable argument list whose contents are accessed based on the\r
328 format string specified by FormatString.\r
329\r
330 @return The number of Unicode characters in the produced output buffer not including the\r
331 Null-terminator.\r
332\r
333**/\r
334UINTN\r
335EFIAPI\r
336UnicodeSPrintAsciiFormat (\r
337 OUT CHAR16 *StartOfBuffer,\r
338 IN UINTN BufferSize,\r
339 IN CONST CHAR8 *FormatString,\r
340 ...\r
341 )\r
342{\r
343 VA_LIST Marker;\r
344 UINTN NumberOfPrinted;\r
345\r
346 VA_START (Marker, FormatString);\r
347 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
348 VA_END (Marker);\r
349 return NumberOfPrinted;\r
350}\r
351\r
352#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
353\r
354/**\r
355 [ATTENTION] This function is deprecated for security reason.\r
356\r
357 Converts a decimal value to a Null-terminated Unicode string.\r
358 \r
359 Converts the decimal number specified by Value to a Null-terminated Unicode \r
360 string specified by Buffer containing at most Width characters. No padding of spaces \r
361 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
362 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
363 If the conversion contains more than Width characters, then only the first\r
364 Width characters are returned, and the total number of characters \r
365 required to perform the conversion is returned.\r
366 Additional conversion parameters are specified in Flags. \r
367 \r
368 The Flags bit LEFT_JUSTIFY is always ignored.\r
369 All conversions are left justified in Buffer.\r
370 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
371 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
372 are inserted every 3rd digit starting from the right.\r
373 If RADIX_HEX is set in Flags, then the output buffer will be \r
374 formatted in hexadecimal format.\r
375 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
376 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
377 then Buffer is padded with '0' characters so the combination of the optional '-' \r
378 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
379 add up to Width characters.\r
380 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
381 If Buffer is NULL, then ASSERT().\r
382 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
383 If unsupported bits are set in Flags, then ASSERT().\r
384 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
385 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
386\r
387 @param Buffer The pointer to the output buffer for the produced Null-terminated\r
388 Unicode string.\r
389 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
390 @param Value The 64-bit signed value to convert to a string.\r
391 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
392 the Null-terminator.\r
393 \r
394 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
395\r
396**/\r
397UINTN\r
398EFIAPI\r
399UnicodeValueToString (\r
400 IN OUT CHAR16 *Buffer,\r
401 IN UINTN Flags,\r
402 IN INT64 Value,\r
403 IN UINTN Width\r
404 )\r
405{\r
406 ASSERT_UNICODE_BUFFER(Buffer);\r
407 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);\r
408}\r
409\r
410#endif\r
411\r
412/**\r
413 Converts a decimal value to a Null-terminated Unicode string.\r
414\r
415 Converts the decimal number specified by Value to a Null-terminated Unicode\r
416 string specified by Buffer containing at most Width characters. No padding of\r
417 spaces is ever performed. If Width is 0 then a width of\r
418 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
419 Width characters, then only the first Width characters are placed in Buffer.\r
420 Additional conversion parameters are specified in Flags.\r
421\r
422 The Flags bit LEFT_JUSTIFY is always ignored.\r
423 All conversions are left justified in Buffer.\r
424 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
425 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
426 commas are inserted every 3rd digit starting from the right.\r
427 If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
428 hexadecimal format.\r
429 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
430 Buffer is a '-'.\r
431 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
432 Buffer is padded with '0' characters so the combination of the optional '-'\r
433 sign character, '0' characters, digit characters for Value, and the\r
434 Null-terminator add up to Width characters.\r
435\r
436 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
437 If an error would be returned, then the function will also ASSERT().\r
438\r
439 @param Buffer The pointer to the output buffer for the produced\r
440 Null-terminated Unicode string.\r
441 @param BufferSize The size of Buffer in bytes, including the\r
442 Null-terminator.\r
443 @param Flags The bitmask of flags that specify left justification,\r
444 zero pad, and commas.\r
445 @param Value The 64-bit signed value to convert to a string.\r
446 @param Width The maximum number of Unicode characters to place in\r
447 Buffer, not including the Null-terminator.\r
448\r
449 @retval RETURN_SUCCESS The decimal value is converted.\r
450 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r
451 value.\r
452 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
453 If PcdMaximumUnicodeStringLength is not\r
454 zero, and BufferSize is greater than\r
455 (PcdMaximumUnicodeStringLength *\r
456 sizeof (CHAR16) + 1).\r
457 If unsupported bits are set in Flags.\r
458 If both COMMA_TYPE and RADIX_HEX are set in\r
459 Flags.\r
460 If Width >= MAXIMUM_VALUE_CHARACTERS.\r
461\r
462**/\r
463RETURN_STATUS\r
464EFIAPI\r
465UnicodeValueToStringS (\r
466 IN OUT CHAR16 *Buffer,\r
467 IN UINTN BufferSize,\r
468 IN UINTN Flags,\r
469 IN INT64 Value,\r
470 IN UINTN Width\r
471 )\r
472{\r
473 ASSERT_UNICODE_BUFFER(Buffer);\r
474 return BasePrintLibConvertValueToStringS ((CHAR8 *)Buffer, BufferSize, Flags, Value, Width, 2);\r
475}\r
476\r
477/**\r
478 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
479 ASCII format string and a VA_LIST argument list.\r
480\r
481 This function is similar as vsnprintf_s defined in C11.\r
482\r
483 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
484 and BufferSize.\r
485 The ASCII string is produced by parsing the format string specified by FormatString.\r
486 Arguments are pulled from the variable argument list specified by Marker based on\r
487 the contents of the format string.\r
488 The number of ASCII characters in the produced output buffer is returned not including\r
489 the Null-terminator.\r
490\r
491 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
492 unmodified and 0 is returned.\r
493 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
494 unmodified and 0 is returned.\r
495 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
496 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
497 is unmodified and 0 is returned.\r
498 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
499 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
500 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
501\r
502 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
503\r
504 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
505 ASCII string.\r
506 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
507 @param FormatString A Null-terminated ASCII format string.\r
508 @param Marker VA_LIST marker for the variable argument list.\r
509\r
510 @return The number of ASCII characters in the produced output buffer not including the\r
511 Null-terminator.\r
512\r
513**/\r
514UINTN\r
515EFIAPI\r
516AsciiVSPrint (\r
517 OUT CHAR8 *StartOfBuffer,\r
518 IN UINTN BufferSize,\r
519 IN CONST CHAR8 *FormatString,\r
520 IN VA_LIST Marker\r
521 )\r
522{\r
523 return BasePrintLibSPrintMarker (StartOfBuffer, BufferSize, 0, FormatString, Marker, NULL);\r
524}\r
525\r
526/**\r
527 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
528 ASCII format string and a BASE_LIST argument list.\r
529\r
530 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
531 and BufferSize.\r
532 The ASCII string is produced by parsing the format string specified by FormatString.\r
533 Arguments are pulled from the variable argument list specified by Marker based on\r
534 the contents of the format string.\r
535 The number of ASCII characters in the produced output buffer is returned not including\r
536 the Null-terminator.\r
537\r
538 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
539 unmodified and 0 is returned.\r
540 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
541 unmodified and 0 is returned.\r
542 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
543 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
544 is unmodified and 0 is returned.\r
545 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
546 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
547 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
548\r
549 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
550\r
551 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
552 ASCII string.\r
553 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
554 @param FormatString A Null-terminated ASCII format string.\r
555 @param Marker BASE_LIST marker for the variable argument list.\r
556\r
557 @return The number of ASCII characters in the produced output buffer not including the\r
558 Null-terminator.\r
559\r
560**/\r
561UINTN\r
562EFIAPI\r
563AsciiBSPrint (\r
564 OUT CHAR8 *StartOfBuffer,\r
565 IN UINTN BufferSize,\r
566 IN CONST CHAR8 *FormatString,\r
567 IN BASE_LIST Marker\r
568 )\r
569{\r
570 return BasePrintLibSPrintMarker (StartOfBuffer, BufferSize, 0, FormatString, gNullVaList, Marker);\r
571}\r
572\r
573/**\r
574 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
575 ASCII format string and variable argument list.\r
576\r
577 This function is similar as snprintf_s defined in C11.\r
578\r
579 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
580 and BufferSize.\r
581 The ASCII string is produced by parsing the format string specified by FormatString.\r
582 Arguments are pulled from the variable argument list based on the contents of the\r
583 format string.\r
584 The number of ASCII characters in the produced output buffer is returned not including\r
585 the Null-terminator.\r
586\r
587 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
588 unmodified and 0 is returned.\r
589 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
590 unmodified and 0 is returned.\r
591 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
592 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
593 is unmodified and 0 is returned.\r
594 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
595 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
596 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
597\r
598 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
599\r
600 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
601 ASCII string.\r
602 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
603 @param FormatString A Null-terminated ASCII format string.\r
604 @param ... Variable argument list whose contents are accessed based on the\r
605 format string specified by FormatString.\r
606\r
607 @return The number of ASCII characters in the produced output buffer not including the\r
608 Null-terminator.\r
609\r
610**/\r
611UINTN\r
612EFIAPI\r
613AsciiSPrint (\r
614 OUT CHAR8 *StartOfBuffer,\r
615 IN UINTN BufferSize,\r
616 IN CONST CHAR8 *FormatString,\r
617 ...\r
618 )\r
619{\r
620 VA_LIST Marker;\r
621 UINTN NumberOfPrinted;\r
622\r
623 VA_START (Marker, FormatString);\r
624 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
625 VA_END (Marker);\r
626 return NumberOfPrinted;\r
627}\r
628\r
629/**\r
630 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
631 Unicode format string and a VA_LIST argument list.\r
632\r
633 This function is similar as vsnprintf_s defined in C11.\r
634\r
635 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
636 and BufferSize.\r
637 The ASCII string is produced by parsing the format string specified by FormatString.\r
638 Arguments are pulled from the variable argument list specified by Marker based on\r
639 the contents of the format string.\r
640 The number of ASCII characters in the produced output buffer is returned not including\r
641 the Null-terminator.\r
642\r
643 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
644\r
645 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
646 unmodified and 0 is returned.\r
647 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
648 unmodified and 0 is returned.\r
649 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
650 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
651 is unmodified and 0 is returned.\r
652 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
653 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
654 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
655\r
656 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
657\r
658 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
659 ASCII string.\r
660 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
661 @param FormatString A Null-terminated Unicode format string.\r
662 @param Marker VA_LIST marker for the variable argument list.\r
663\r
664 @return The number of ASCII characters in the produced output buffer not including the\r
665 Null-terminator.\r
666\r
667**/\r
668UINTN\r
669EFIAPI\r
670AsciiVSPrintUnicodeFormat (\r
671 OUT CHAR8 *StartOfBuffer,\r
672 IN UINTN BufferSize,\r
673 IN CONST CHAR16 *FormatString,\r
674 IN VA_LIST Marker\r
675 )\r
676{\r
677 ASSERT_UNICODE_BUFFER (FormatString);\r
678 return BasePrintLibSPrintMarker (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker, NULL);\r
679}\r
680\r
681/**\r
682 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
683 Unicode format string and a BASE_LIST argument list.\r
684\r
685 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
686 and BufferSize.\r
687 The ASCII string is produced by parsing the format string specified by FormatString.\r
688 Arguments are pulled from the variable argument list specified by Marker based on\r
689 the contents of the format string.\r
690 The number of ASCII characters in the produced output buffer is returned not including\r
691 the Null-terminator.\r
692\r
693 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
694\r
695 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
696 unmodified and 0 is returned.\r
697 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
698 unmodified and 0 is returned.\r
699 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
700 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
701 is unmodified and 0 is returned.\r
702 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
703 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
704 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
705\r
706 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
707\r
708 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
709 ASCII string.\r
710 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
711 @param FormatString A Null-terminated Unicode format string.\r
712 @param Marker BASE_LIST marker for the variable argument list.\r
713\r
714 @return The number of ASCII characters in the produced output buffer not including the\r
715 Null-terminator.\r
716\r
717**/\r
718UINTN\r
719EFIAPI\r
720AsciiBSPrintUnicodeFormat (\r
721 OUT CHAR8 *StartOfBuffer,\r
722 IN UINTN BufferSize,\r
723 IN CONST CHAR16 *FormatString,\r
724 IN BASE_LIST Marker\r
725 )\r
726{\r
727 ASSERT_UNICODE_BUFFER (FormatString);\r
728 return BasePrintLibSPrintMarker (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, gNullVaList, Marker);\r
729}\r
730\r
731/**\r
732 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
733 Unicode format string and variable argument list.\r
734\r
735 This function is similar as snprintf_s defined in C11.\r
736\r
737 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
738 and BufferSize.\r
739 The ASCII string is produced by parsing the format string specified by FormatString.\r
740 Arguments are pulled from the variable argument list based on the contents of the\r
741 format string.\r
742 The number of ASCII characters in the produced output buffer is returned not including\r
743 the Null-terminator.\r
744\r
745 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
746\r
747 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
748 unmodified and 0 is returned.\r
749 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
750 unmodified and 0 is returned.\r
751 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
752 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
753 is unmodified and 0 is returned.\r
754 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
755 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
756 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
757\r
758 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
759\r
760 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
761 ASCII string.\r
762 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
763 @param FormatString A Null-terminated Unicode format string.\r
764 @param ... Variable argument list whose contents are accessed based on the\r
765 format string specified by FormatString.\r
766\r
767 @return The number of ASCII characters in the produced output buffer not including the\r
768 Null-terminator.\r
769\r
770**/\r
771UINTN\r
772EFIAPI\r
773AsciiSPrintUnicodeFormat (\r
774 OUT CHAR8 *StartOfBuffer,\r
775 IN UINTN BufferSize,\r
776 IN CONST CHAR16 *FormatString,\r
777 ...\r
778 )\r
779{\r
780 VA_LIST Marker;\r
781 UINTN NumberOfPrinted;\r
782\r
783 VA_START (Marker, FormatString);\r
784 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
785 VA_END (Marker);\r
786 return NumberOfPrinted;\r
787}\r
788\r
789\r
790#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
791\r
792/**\r
793 [ATTENTION] This function is deprecated for security reason.\r
794\r
795 Converts a decimal value to a Null-terminated ASCII string.\r
796 \r
797 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
798 specified by Buffer containing at most Width characters. No padding of spaces \r
799 is ever performed.\r
800 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
801 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
802 If the conversion contains more than Width characters, then only the first Width\r
803 characters are returned, and the total number of characters required to perform\r
804 the conversion is returned.\r
805 Additional conversion parameters are specified in Flags. \r
806 The Flags bit LEFT_JUSTIFY is always ignored.\r
807 All conversions are left justified in Buffer.\r
808 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
809 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
810 are inserted every 3rd digit starting from the right.\r
811 If RADIX_HEX is set in Flags, then the output buffer will be \r
812 formatted in hexadecimal format.\r
813 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
814 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
815 then Buffer is padded with '0' characters so the combination of the optional '-' \r
816 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
817 add up to Width characters.\r
818 \r
819 If Buffer is NULL, then ASSERT().\r
820 If unsupported bits are set in Flags, then ASSERT().\r
821 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
822 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
823\r
824 @param Buffer The pointer to the output buffer for the produced Null-terminated\r
825 ASCII string.\r
826 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
827 @param Value The 64-bit signed value to convert to a string.\r
828 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
829 the Null-terminator.\r
830 \r
831 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
832\r
833**/\r
834UINTN\r
835EFIAPI\r
836AsciiValueToString (\r
837 OUT CHAR8 *Buffer,\r
838 IN UINTN Flags,\r
839 IN INT64 Value,\r
840 IN UINTN Width\r
841 )\r
842{\r
843 return BasePrintLibConvertValueToString (Buffer, Flags, Value, Width, 1);\r
844}\r
845\r
846#endif\r
847\r
848/**\r
849 Converts a decimal value to a Null-terminated Ascii string.\r
850\r
851 Converts the decimal number specified by Value to a Null-terminated Ascii\r
852 string specified by Buffer containing at most Width characters. No padding of\r
853 spaces is ever performed. If Width is 0 then a width of\r
854 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
855 Width characters, then only the first Width characters are placed in Buffer.\r
856 Additional conversion parameters are specified in Flags.\r
857\r
858 The Flags bit LEFT_JUSTIFY is always ignored.\r
859 All conversions are left justified in Buffer.\r
860 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
861 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
862 commas are inserted every 3rd digit starting from the right.\r
863 If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
864 hexadecimal format.\r
865 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
866 Buffer is a '-'.\r
867 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
868 Buffer is padded with '0' characters so the combination of the optional '-'\r
869 sign character, '0' characters, digit characters for Value, and the\r
870 Null-terminator add up to Width characters.\r
871\r
872 If an error would be returned, then the function will ASSERT().\r
873\r
874 @param Buffer The pointer to the output buffer for the produced\r
875 Null-terminated Ascii string.\r
876 @param BufferSize The size of Buffer in bytes, including the\r
877 Null-terminator.\r
878 @param Flags The bitmask of flags that specify left justification,\r
879 zero pad, and commas.\r
880 @param Value The 64-bit signed value to convert to a string.\r
881 @param Width The maximum number of Ascii characters to place in\r
882 Buffer, not including the Null-terminator.\r
883\r
884 @retval RETURN_SUCCESS The decimal value is converted.\r
885 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r
886 value.\r
887 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
888 If PcdMaximumAsciiStringLength is not\r
889 zero, and BufferSize is greater than\r
890 PcdMaximumAsciiStringLength.\r
891 If unsupported bits are set in Flags.\r
892 If both COMMA_TYPE and RADIX_HEX are set in\r
893 Flags.\r
894 If Width >= MAXIMUM_VALUE_CHARACTERS.\r
895\r
896**/\r
897RETURN_STATUS\r
898EFIAPI\r
899AsciiValueToStringS (\r
900 IN OUT CHAR8 *Buffer,\r
901 IN UINTN BufferSize,\r
902 IN UINTN Flags,\r
903 IN INT64 Value,\r
904 IN UINTN Width\r
905 )\r
906{\r
907 return BasePrintLibConvertValueToStringS (Buffer, BufferSize, Flags, Value, Width, 1);\r
908}\r
909\r
910/**\r
911 Returns the number of characters that would be produced by if the formatted \r
912 output were produced not including the Null-terminator.\r
913\r
914 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
915\r
916 If FormatString is NULL, then ASSERT() and 0 is returned.\r
917 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more\r
918 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
919 Null-terminator, then ASSERT() and 0 is returned.\r
920\r
921 @param[in] FormatString A Null-terminated Unicode format string.\r
922 @param[in] Marker VA_LIST marker for the variable argument list.\r
923\r
924 @return The number of characters that would be produced, not including the \r
925 Null-terminator.\r
926**/\r
927UINTN\r
928EFIAPI\r
929SPrintLength (\r
930 IN CONST CHAR16 *FormatString,\r
931 IN VA_LIST Marker\r
932 )\r
933{\r
934 ASSERT_UNICODE_BUFFER (FormatString);\r
935 return BasePrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
936}\r
937\r
938/**\r
939 Returns the number of characters that would be produced by if the formatted \r
940 output were produced not including the Null-terminator.\r
941\r
942 If FormatString is NULL, then ASSERT() and 0 is returned.\r
943 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more\r
944 than PcdMaximumAsciiStringLength Ascii characters not including the\r
945 Null-terminator, then ASSERT() and 0 is returned.\r
946\r
947 @param[in] FormatString A Null-terminated ASCII format string.\r
948 @param[in] Marker VA_LIST marker for the variable argument list.\r
949\r
950 @return The number of characters that would be produced, not including the \r
951 Null-terminator.\r
952**/\r
953UINTN\r
954EFIAPI\r
955SPrintLengthAsciiFormat (\r
956 IN CONST CHAR8 *FormatString,\r
957 IN VA_LIST Marker\r
958 )\r
959{\r
960 return BasePrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
961}\r