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