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