VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePrintLib/PrintLib.c@ 99396

最後變更 在這個檔案從99396是 89983,由 vboxsync 提交於 4 年 前

Devices/EFI: Merge edk-stable202105 and openssl 1.1.1j and make it build, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette