]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
MdePkg/BasePrintLib: Fix incomplete print output
[mirror_edk2.git] / MdeModulePkg / Library / DxePrintLibPrint2Protocol / PrintLib.c
... / ...
CommitLineData
1/** @file\r
2 Instance of Print Library based on gEfiPrint2SProtocolGuid.\r
3\r
4 Implement the print library instance by wrap the interface \r
5 provided in the Print2S protocol. This protocol is defined as the internal\r
6 protocol related to this implementation, not in the public spec. So, this \r
7 library instance is only for this code base.\r
8\r
9Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
10This program and the accompanying materials\r
11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#include <Uefi.h>\r
21#include <Base.h>\r
22#include <Protocol/Print2.h>\r
23\r
24#include <Library/PrintLib.h>\r
25\r
26#include <Library/BaseLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/PcdLib.h>\r
29\r
30#define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)\r
31\r
32//\r
33// Safe print checks\r
34//\r
35#define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength))\r
36#define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength))\r
37\r
38#define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \\r
39 do { \\r
40 ASSERT (Expression); \\r
41 if (!(Expression)) { \\r
42 return RetVal; \\r
43 } \\r
44 } while (FALSE)\r
45\r
46EFI_PRINT2S_PROTOCOL *mPrint2SProtocol = NULL;\r
47\r
48/**\r
49 The constructor function caches the pointer to Print2S protocol.\r
50 \r
51 The constructor function locates Print2S protocol from protocol database.\r
52 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
53\r
54 @param ImageHandle The firmware allocated handle for the EFI image.\r
55 @param SystemTable A pointer to the EFI System Table.\r
56 \r
57 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
58\r
59**/\r
60EFI_STATUS\r
61EFIAPI\r
62PrintLibConstructor (\r
63 IN EFI_HANDLE ImageHandle,\r
64 IN EFI_SYSTEM_TABLE *SystemTable\r
65 )\r
66{\r
67 EFI_STATUS Status;\r
68\r
69 Status = SystemTable->BootServices->LocateProtocol (\r
70 &gEfiPrint2SProtocolGuid,\r
71 NULL,\r
72 (VOID**) &mPrint2SProtocol\r
73 );\r
74 ASSERT_EFI_ERROR (Status);\r
75 ASSERT (mPrint2SProtocol != NULL);\r
76\r
77 return Status;\r
78}\r
79\r
80\r
81/**\r
82 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated \r
83 format string.\r
84\r
85 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.\r
86 @param Format Null-terminated format string.\r
87 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.\r
88 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.\r
89 @param Size The size, in bytes, of the BaseListMarker buffer.\r
90\r
91 @return TRUE The VA_LIST has been converted to BASE_LIST.\r
92 @return FALSE The VA_LIST has not been converted to BASE_LIST.\r
93\r
94**/\r
95BOOLEAN\r
96DxePrintLibPrint2ProtocolVaListToBaseList (\r
97 IN BOOLEAN AsciiFormat,\r
98 IN CONST CHAR8 *Format,\r
99 IN VA_LIST VaListMarker,\r
100 OUT BASE_LIST BaseListMarker,\r
101 IN UINTN Size\r
102 )\r
103{\r
104 BASE_LIST BaseListStart;\r
105 UINTN BytesPerFormatCharacter;\r
106 UINTN FormatMask;\r
107 UINTN FormatCharacter;\r
108 BOOLEAN Long;\r
109 BOOLEAN Done;\r
110\r
111 ASSERT (BaseListMarker != NULL);\r
112 SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), FALSE);\r
113\r
114 BaseListStart = BaseListMarker;\r
115\r
116 if (AsciiFormat) {\r
117 if (ASCII_RSIZE_MAX != 0) {\r
118 SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), FALSE);\r
119 }\r
120 BytesPerFormatCharacter = 1;\r
121 FormatMask = 0xff;\r
122 } else {\r
123 if (RSIZE_MAX != 0) {\r
124 SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), FALSE);\r
125 }\r
126 BytesPerFormatCharacter = 2;\r
127 FormatMask = 0xffff;\r
128 }\r
129\r
130 //\r
131 // Get the first character from the format string\r
132 //\r
133 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
134\r
135 while (FormatCharacter != 0) {\r
136 if (FormatCharacter == '%') {\r
137 Long = FALSE;\r
138\r
139 //\r
140 // Parse Flags and Width\r
141 //\r
142 for (Done = FALSE; !Done; ) {\r
143 //\r
144 // Get the next character from the format string\r
145 //\r
146 Format += BytesPerFormatCharacter;\r
147\r
148 //\r
149 // Get the next character from the format string\r
150 //\r
151 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
152\r
153 switch (FormatCharacter) {\r
154 case '.': \r
155 case '-': \r
156 case '+': \r
157 case ' ': \r
158 case ',': \r
159 case '0':\r
160 case '1':\r
161 case '2':\r
162 case '3':\r
163 case '4':\r
164 case '5':\r
165 case '6':\r
166 case '7':\r
167 case '8':\r
168 case '9':\r
169 break;\r
170 case 'L':\r
171 case 'l': \r
172 Long = TRUE;\r
173 break;\r
174 case '*':\r
175 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
176 break;\r
177 case '\0':\r
178 //\r
179 // Make no output if Format string terminates unexpectedly when\r
180 // looking up for flag, width, precision and type. \r
181 //\r
182 Format -= BytesPerFormatCharacter;\r
183 //\r
184 // break skipped on purpose.\r
185 //\r
186 default:\r
187 Done = TRUE;\r
188 break;\r
189 }\r
190 } \r
191 \r
192 //\r
193 // Handle each argument type\r
194 //\r
195 switch (FormatCharacter) {\r
196 case 'p':\r
197 if (sizeof (VOID *) > 4) {\r
198 Long = TRUE;\r
199 }\r
200 case 'X':\r
201 case 'x':\r
202 case 'u':\r
203 case 'd':\r
204 if (Long) {\r
205 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
206 } else {\r
207 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
208 }\r
209 break;\r
210 case 's':\r
211 case 'S':\r
212 case 'a':\r
213 case 'g':\r
214 case 't':\r
215 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
216 break;\r
217 case 'c':\r
218 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
219 break;\r
220 case 'r':\r
221 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
222 break;\r
223 }\r
224 }\r
225\r
226 //\r
227 // If BASE_LIST is larger than Size, then return FALSE\r
228 //\r
229 if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {\r
230 DEBUG ((DEBUG_ERROR, "The input variable argument list is too long. Please consider breaking into multiple print calls.\n"));\r
231 return FALSE;\r
232 }\r
233\r
234 //\r
235 // Get the next character from the format string\r
236 //\r
237 Format += BytesPerFormatCharacter;\r
238\r
239 //\r
240 // Get the next character from the format string\r
241 //\r
242 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
243 }\r
244 return TRUE;\r
245}\r
246\r
247/**\r
248 Produces a Null-terminated Unicode string in an output buffer based on\r
249 a Null-terminated Unicode format string and a VA_LIST argument list.\r
250\r
251 This function is similar as vsnprintf_s defined in C11.\r
252\r
253 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
254 and BufferSize.\r
255 The Unicode string is produced by parsing the format string specified by FormatString.\r
256 Arguments are pulled from the variable argument list specified by Marker based on the\r
257 contents of the format string.\r
258 The number of Unicode characters in the produced output buffer is returned not including\r
259 the Null-terminator.\r
260\r
261 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
262 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
263\r
264 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
265 unmodified and 0 is returned.\r
266 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
267 unmodified and 0 is returned.\r
268 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
269 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
270 buffer is unmodified and 0 is returned.\r
271 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
272 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
273 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
274\r
275 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
276\r
277 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
278 Unicode string.\r
279 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
280 @param FormatString A Null-terminated Unicode format string.\r
281 @param Marker VA_LIST marker for the variable argument list.\r
282\r
283 @return The number of Unicode characters in the produced output buffer not including the\r
284 Null-terminator.\r
285\r
286**/\r
287UINTN\r
288EFIAPI\r
289UnicodeVSPrint (\r
290 OUT CHAR16 *StartOfBuffer,\r
291 IN UINTN BufferSize,\r
292 IN CONST CHAR16 *FormatString,\r
293 IN VA_LIST Marker\r
294 )\r
295{\r
296 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
297 BOOLEAN Converted;\r
298\r
299 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
300 ASSERT_UNICODE_BUFFER (FormatString);\r
301\r
302 Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r
303 FALSE,\r
304 (CHAR8 *)FormatString,\r
305 Marker,\r
306 (BASE_LIST)BaseListMarker,\r
307 sizeof (BaseListMarker) - 8\r
308 );\r
309 if (!Converted) {\r
310 return 0;\r
311 }\r
312\r
313 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
314}\r
315\r
316/**\r
317 Produces a Null-terminated Unicode string in an output buffer based on\r
318 a Null-terminated Unicode format string and a BASE_LIST argument list.\r
319\r
320 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
321 and BufferSize.\r
322 The Unicode string is produced by parsing the format string specified by FormatString.\r
323 Arguments are pulled from the variable argument list specified by Marker based on the\r
324 contents of the format string.\r
325 The number of Unicode characters in the produced output buffer is returned not including\r
326 the Null-terminator.\r
327\r
328 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
329 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
330\r
331 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
332 unmodified and 0 is returned.\r
333 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
334 unmodified and 0 is returned.\r
335 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
336 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
337 buffer is unmodified and 0 is returned.\r
338 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
339 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
340 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
341\r
342 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
343\r
344 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
345 Unicode string.\r
346 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
347 @param FormatString A Null-terminated Unicode format string.\r
348 @param Marker BASE_LIST marker for the variable argument list.\r
349\r
350 @return The number of Unicode characters in the produced output buffer not including the\r
351 Null-terminator.\r
352\r
353**/\r
354UINTN\r
355EFIAPI\r
356UnicodeBSPrint (\r
357 OUT CHAR16 *StartOfBuffer,\r
358 IN UINTN BufferSize,\r
359 IN CONST CHAR16 *FormatString,\r
360 IN BASE_LIST Marker\r
361 )\r
362{\r
363 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
364 ASSERT_UNICODE_BUFFER (FormatString);\r
365 return mPrint2SProtocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
366}\r
367\r
368/**\r
369 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
370 Unicode format string and variable argument list.\r
371\r
372 This function is similar as snprintf_s defined in C11.\r
373\r
374 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
375 and BufferSize.\r
376 The Unicode string is produced by parsing the format string specified by FormatString.\r
377 Arguments are pulled from the variable argument list based on the contents of the format string.\r
378 The number of Unicode characters in the produced output buffer is returned not including\r
379 the Null-terminator.\r
380\r
381 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
382 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
383\r
384 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
385 unmodified and 0 is returned.\r
386 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
387 unmodified and 0 is returned.\r
388 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
389 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
390 buffer is unmodified and 0 is returned.\r
391 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
392 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
393 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
394\r
395 If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r
396\r
397 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
398 Unicode string.\r
399 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
400 @param FormatString A Null-terminated Unicode format string.\r
401 @param ... Variable argument list whose contents are accessed based on the\r
402 format string specified by FormatString.\r
403\r
404 @return The number of Unicode characters in the produced output buffer not including the\r
405 Null-terminator.\r
406\r
407**/\r
408UINTN\r
409EFIAPI\r
410UnicodeSPrint (\r
411 OUT CHAR16 *StartOfBuffer,\r
412 IN UINTN BufferSize,\r
413 IN CONST CHAR16 *FormatString,\r
414 ...\r
415 )\r
416{\r
417 VA_LIST Marker;\r
418 UINTN NumberOfPrinted;\r
419\r
420 VA_START (Marker, FormatString);\r
421 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
422 VA_END (Marker);\r
423 return NumberOfPrinted;\r
424}\r
425\r
426/**\r
427 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
428 ASCII format string and a VA_LIST argument list.\r
429\r
430 This function is similar as vsnprintf_s defined in C11.\r
431\r
432 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
433 and BufferSize.\r
434 The Unicode string is produced by parsing the format string specified by FormatString.\r
435 Arguments are pulled from the variable argument list specified by Marker based on the\r
436 contents of the format string.\r
437 The number of Unicode characters in the produced output buffer is returned not including\r
438 the Null-terminator.\r
439\r
440 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
441\r
442 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
443 unmodified and 0 is returned.\r
444 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
445 unmodified and 0 is returned.\r
446 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
447 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
448 buffer is unmodified and 0 is returned.\r
449 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
450 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
451 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
452\r
453 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
454\r
455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
456 Unicode string.\r
457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
458 @param FormatString A Null-terminated ASCII format string.\r
459 @param Marker VA_LIST marker for the variable argument list.\r
460\r
461 @return The number of Unicode characters in the produced output buffer not including the\r
462 Null-terminator.\r
463\r
464**/\r
465UINTN\r
466EFIAPI\r
467UnicodeVSPrintAsciiFormat (\r
468 OUT CHAR16 *StartOfBuffer,\r
469 IN UINTN BufferSize,\r
470 IN CONST CHAR8 *FormatString,\r
471 IN VA_LIST Marker\r
472 )\r
473{\r
474 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
475 BOOLEAN Converted;\r
476\r
477 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
478\r
479 Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r
480 TRUE,\r
481 FormatString,\r
482 Marker,\r
483 (BASE_LIST)BaseListMarker,\r
484 sizeof (BaseListMarker) - 8\r
485 );\r
486 if (!Converted) {\r
487 return 0;\r
488 }\r
489\r
490 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
491}\r
492\r
493/**\r
494 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
495 ASCII format string and a BASE_LIST argument list.\r
496\r
497 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
498 and BufferSize.\r
499 The Unicode string is produced by parsing the format string specified by FormatString.\r
500 Arguments are pulled from the variable argument list specified by Marker based on the\r
501 contents of the format string.\r
502 The number of Unicode characters in the produced output buffer is returned not including\r
503 the Null-terminator.\r
504\r
505 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
506\r
507 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
508 unmodified and 0 is returned.\r
509 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
510 unmodified and 0 is returned.\r
511 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
512 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
513 buffer is unmodified and 0 is returned.\r
514 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
515 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
516 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
517\r
518 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
519\r
520 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
521 Unicode string.\r
522 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
523 @param FormatString A Null-terminated ASCII format string.\r
524 @param Marker BASE_LIST marker for the variable argument list.\r
525\r
526 @return The number of Unicode characters in the produced output buffer not including the\r
527 Null-terminator.\r
528\r
529**/\r
530UINTN\r
531EFIAPI\r
532UnicodeBSPrintAsciiFormat (\r
533 OUT CHAR16 *StartOfBuffer,\r
534 IN UINTN BufferSize,\r
535 IN CONST CHAR8 *FormatString,\r
536 IN BASE_LIST Marker\r
537 )\r
538{\r
539 ASSERT_UNICODE_BUFFER (StartOfBuffer);\r
540 return mPrint2SProtocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
541}\r
542\r
543/**\r
544 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
545 ASCII format string and variable argument list.\r
546\r
547 This function is similar as snprintf_s defined in C11.\r
548\r
549 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
550 and BufferSize.\r
551 The Unicode string is produced by parsing the format string specified by FormatString.\r
552 Arguments are pulled from the variable argument list based on the contents of the\r
553 format string.\r
554 The number of Unicode characters in the produced output buffer is returned not including\r
555 the Null-terminator.\r
556\r
557 If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
558\r
559 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
560 unmodified and 0 is returned.\r
561 If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
562 unmodified and 0 is returned.\r
563 If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r
564 (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r
565 buffer is unmodified and 0 is returned.\r
566 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
567 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
568 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
569\r
570 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
571\r
572 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
573 Unicode string.\r
574 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
575 @param FormatString A Null-terminated ASCII format string.\r
576 @param ... Variable argument list whose contents are accessed based on the\r
577 format string specified by FormatString.\r
578\r
579 @return The number of Unicode characters in the produced output buffer not including the\r
580 Null-terminator.\r
581\r
582**/\r
583UINTN\r
584EFIAPI\r
585UnicodeSPrintAsciiFormat (\r
586 OUT CHAR16 *StartOfBuffer,\r
587 IN UINTN BufferSize,\r
588 IN CONST CHAR8 *FormatString,\r
589 ...\r
590 )\r
591{\r
592 VA_LIST Marker;\r
593 UINTN NumberOfPrinted;\r
594\r
595 VA_START (Marker, FormatString);\r
596 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
597 VA_END (Marker);\r
598 return NumberOfPrinted;\r
599}\r
600\r
601#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
602\r
603/**\r
604 [ATTENTION] This function is deprecated for security reason.\r
605\r
606 Converts a decimal value to a Null-terminated Unicode string.\r
607 \r
608 Converts the decimal number specified by Value to a Null-terminated Unicode \r
609 string specified by Buffer containing at most Width characters. No padding of spaces \r
610 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
611 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
612 If the conversion contains more than Width characters, then only the first\r
613 Width characters are returned, and the total number of characters \r
614 required to perform the conversion is returned.\r
615 Additional conversion parameters are specified in Flags. \r
616 \r
617 The Flags bit LEFT_JUSTIFY is always ignored.\r
618 All conversions are left justified in Buffer.\r
619 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
620 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
621 are inserted every 3rd digit starting from the right.\r
622 If RADIX_HEX is set in Flags, then the output buffer will be \r
623 formatted in hexadecimal format.\r
624 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
625 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
626 then Buffer is padded with '0' characters so the combination of the optional '-' \r
627 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
628 add up to Width characters.\r
629 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
630 If Buffer is NULL, then ASSERT().\r
631 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
632 If unsupported bits are set in Flags, then ASSERT().\r
633 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
634 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
635\r
636 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
637 Unicode string.\r
638 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
639 @param Value The 64-bit signed value to convert to a string.\r
640 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
641 the Null-terminator.\r
642 \r
643 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
644\r
645**/\r
646UINTN\r
647EFIAPI\r
648UnicodeValueToString (\r
649 IN OUT CHAR16 *Buffer,\r
650 IN UINTN Flags,\r
651 IN INT64 Value,\r
652 IN UINTN Width\r
653 )\r
654{\r
655 RETURN_STATUS Status;\r
656 UINTN BufferSize;\r
657\r
658 if (Width == 0) {\r
659 BufferSize = (MAXIMUM_VALUE_CHARACTERS + 1) * sizeof (CHAR16);\r
660 } else {\r
661 BufferSize = (Width + 1) * sizeof (CHAR16);\r
662 }\r
663\r
664 Status = mPrint2SProtocol->UnicodeValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r
665 if (RETURN_ERROR (Status)) {\r
666 return 0;\r
667 }\r
668\r
669 return StrnLenS (Buffer, BufferSize / sizeof (CHAR16));\r
670}\r
671\r
672#endif\r
673\r
674/**\r
675 Converts a decimal value to a Null-terminated Unicode string.\r
676\r
677 Converts the decimal number specified by Value to a Null-terminated Unicode\r
678 string specified by Buffer containing at most Width characters. No padding of\r
679 spaces is ever performed. If Width is 0 then a width of\r
680 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
681 Width characters, then only the first Width characters are placed in Buffer.\r
682 Additional conversion parameters are specified in Flags.\r
683\r
684 The Flags bit LEFT_JUSTIFY is always ignored.\r
685 All conversions are left justified in Buffer.\r
686 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
687 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
688 commas are inserted every 3rd digit starting from the right.\r
689 If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
690 hexadecimal format.\r
691 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
692 Buffer is a '-'.\r
693 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
694 Buffer is padded with '0' characters so the combination of the optional '-'\r
695 sign character, '0' characters, digit characters for Value, and the\r
696 Null-terminator add up to Width characters.\r
697\r
698 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
699 If an error would be returned, then the function will also ASSERT().\r
700\r
701 @param Buffer The pointer to the output buffer for the produced\r
702 Null-terminated Unicode string.\r
703 @param BufferSize The size of Buffer in bytes, including the\r
704 Null-terminator.\r
705 @param Flags The bitmask of flags that specify left justification,\r
706 zero pad, and commas.\r
707 @param Value The 64-bit signed value to convert to a string.\r
708 @param Width The maximum number of Unicode characters to place in\r
709 Buffer, not including the Null-terminator.\r
710\r
711 @retval RETURN_SUCCESS The decimal value is converted.\r
712 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r
713 value.\r
714 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
715 If PcdMaximumUnicodeStringLength is not\r
716 zero, and BufferSize is greater than\r
717 (PcdMaximumUnicodeStringLength *\r
718 sizeof (CHAR16) + 1).\r
719 If unsupported bits are set in Flags.\r
720 If both COMMA_TYPE and RADIX_HEX are set in\r
721 Flags.\r
722 If Width >= MAXIMUM_VALUE_CHARACTERS.\r
723\r
724**/\r
725RETURN_STATUS\r
726EFIAPI\r
727UnicodeValueToStringS (\r
728 IN OUT CHAR16 *Buffer,\r
729 IN UINTN BufferSize,\r
730 IN UINTN Flags,\r
731 IN INT64 Value,\r
732 IN UINTN Width\r
733 )\r
734{\r
735 return mPrint2SProtocol->UnicodeValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r
736}\r
737\r
738/**\r
739 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
740 ASCII format string and a VA_LIST argument list.\r
741\r
742 This function is similar as vsnprintf_s defined in C11.\r
743\r
744 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
745 and BufferSize.\r
746 The ASCII string is produced by parsing the format string specified by FormatString.\r
747 Arguments are pulled from the variable argument list specified by Marker based on\r
748 the contents of the format string.\r
749 The number of ASCII characters in the produced output buffer is returned not including\r
750 the Null-terminator.\r
751\r
752 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
753 unmodified and 0 is returned.\r
754 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
755 unmodified and 0 is returned.\r
756 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
757 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
758 is unmodified and 0 is returned.\r
759 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
760 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
761 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
762\r
763 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
764\r
765 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
766 ASCII string.\r
767 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
768 @param FormatString A Null-terminated ASCII format string.\r
769 @param Marker VA_LIST marker for the variable argument list.\r
770\r
771 @return The number of ASCII characters in the produced output buffer not including the\r
772 Null-terminator.\r
773\r
774**/\r
775UINTN\r
776EFIAPI\r
777AsciiVSPrint (\r
778 OUT CHAR8 *StartOfBuffer,\r
779 IN UINTN BufferSize,\r
780 IN CONST CHAR8 *FormatString,\r
781 IN VA_LIST Marker\r
782 )\r
783{\r
784 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
785 BOOLEAN Converted;\r
786\r
787 Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r
788 TRUE,\r
789 FormatString,\r
790 Marker,\r
791 (BASE_LIST)BaseListMarker,\r
792 sizeof (BaseListMarker) - 8\r
793 );\r
794 if (!Converted) {\r
795 return 0;\r
796 }\r
797\r
798 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
799}\r
800\r
801/**\r
802 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
803 ASCII format string and a BASE_LIST argument list.\r
804\r
805 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
806 and BufferSize.\r
807 The ASCII string is produced by parsing the format string specified by FormatString.\r
808 Arguments are pulled from the variable argument list specified by Marker based on\r
809 the contents of the format string.\r
810 The number of ASCII characters in the produced output buffer is returned not including\r
811 the Null-terminator.\r
812\r
813 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
814 unmodified and 0 is returned.\r
815 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
816 unmodified and 0 is returned.\r
817 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
818 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
819 is unmodified and 0 is returned.\r
820 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
821 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
822 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
823\r
824 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
825\r
826 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
827 ASCII string.\r
828 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
829 @param FormatString A Null-terminated ASCII format string.\r
830 @param Marker BASE_LIST marker for the variable argument list.\r
831\r
832 @return The number of ASCII characters in the produced output buffer not including the\r
833 Null-terminator.\r
834\r
835**/\r
836UINTN\r
837EFIAPI\r
838AsciiBSPrint (\r
839 OUT CHAR8 *StartOfBuffer,\r
840 IN UINTN BufferSize,\r
841 IN CONST CHAR8 *FormatString,\r
842 IN BASE_LIST Marker\r
843 )\r
844{\r
845 return mPrint2SProtocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
846}\r
847\r
848/**\r
849 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
850 ASCII format string and variable argument list.\r
851\r
852 This function is similar as snprintf_s defined in C11.\r
853\r
854 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
855 and BufferSize.\r
856 The ASCII string is produced by parsing the format string specified by FormatString.\r
857 Arguments are pulled from the variable argument list based on the contents of the\r
858 format string.\r
859 The number of ASCII characters in the produced output buffer is returned not including\r
860 the Null-terminator.\r
861\r
862 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
863 unmodified and 0 is returned.\r
864 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
865 unmodified and 0 is returned.\r
866 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
867 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
868 is unmodified and 0 is returned.\r
869 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
870 PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r
871 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
872\r
873 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
874\r
875 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
876 ASCII string.\r
877 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
878 @param FormatString A Null-terminated ASCII format string.\r
879 @param ... Variable argument list whose contents are accessed based on the\r
880 format string specified by FormatString.\r
881\r
882 @return The number of ASCII characters in the produced output buffer not including the\r
883 Null-terminator.\r
884\r
885**/\r
886UINTN\r
887EFIAPI\r
888AsciiSPrint (\r
889 OUT CHAR8 *StartOfBuffer,\r
890 IN UINTN BufferSize,\r
891 IN CONST CHAR8 *FormatString,\r
892 ...\r
893 )\r
894{\r
895 VA_LIST Marker;\r
896 UINTN NumberOfPrinted;\r
897\r
898 VA_START (Marker, FormatString);\r
899 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
900 VA_END (Marker);\r
901 return NumberOfPrinted;\r
902}\r
903\r
904/**\r
905 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
906 Unicode format string and a VA_LIST argument list.\r
907\r
908 This function is similar as vsnprintf_s defined in C11.\r
909\r
910 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
911 and BufferSize.\r
912 The ASCII string is produced by parsing the format string specified by FormatString.\r
913 Arguments are pulled from the variable argument list specified by Marker based on\r
914 the contents of the format string.\r
915 The number of ASCII characters in the produced output buffer is returned not including\r
916 the Null-terminator.\r
917\r
918 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
919\r
920 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
921 unmodified and 0 is returned.\r
922 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
923 unmodified and 0 is returned.\r
924 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
925 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
926 is unmodified and 0 is returned.\r
927 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
928 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
929 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
930\r
931 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
932\r
933 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
934 ASCII string.\r
935 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
936 @param FormatString A Null-terminated Unicode format string.\r
937 @param Marker VA_LIST marker for the variable argument list.\r
938\r
939 @return The number of ASCII characters in the produced output buffer not including the\r
940 Null-terminator.\r
941\r
942**/\r
943UINTN\r
944EFIAPI\r
945AsciiVSPrintUnicodeFormat (\r
946 OUT CHAR8 *StartOfBuffer,\r
947 IN UINTN BufferSize,\r
948 IN CONST CHAR16 *FormatString,\r
949 IN VA_LIST Marker\r
950 )\r
951{\r
952 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
953 BOOLEAN Converted;\r
954\r
955 ASSERT_UNICODE_BUFFER (FormatString);\r
956\r
957 Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r
958 FALSE,\r
959 (CHAR8 *)FormatString,\r
960 Marker,\r
961 (BASE_LIST)BaseListMarker,\r
962 sizeof (BaseListMarker) - 8\r
963 );\r
964 if (!Converted) {\r
965 return 0;\r
966 }\r
967\r
968 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
969}\r
970\r
971/**\r
972 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
973 Unicode format string and a BASE_LIST argument list.\r
974\r
975 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
976 and BufferSize.\r
977 The ASCII string is produced by parsing the format string specified by FormatString.\r
978 Arguments are pulled from the variable argument list specified by Marker based on\r
979 the contents of the format string.\r
980 The number of ASCII characters in the produced output buffer is returned not including\r
981 the Null-terminator.\r
982\r
983 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
984\r
985 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
986 unmodified and 0 is returned.\r
987 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
988 unmodified and 0 is returned.\r
989 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
990 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
991 is unmodified and 0 is returned.\r
992 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
993 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
994 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
995\r
996 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
997\r
998 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
999 ASCII string.\r
1000 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
1001 @param FormatString A Null-terminated Unicode format string.\r
1002 @param Marker BASE_LIST marker for the variable argument list.\r
1003\r
1004 @return The number of ASCII characters in the produced output buffer not including the\r
1005 Null-terminator.\r
1006\r
1007**/\r
1008UINTN\r
1009EFIAPI\r
1010AsciiBSPrintUnicodeFormat (\r
1011 OUT CHAR8 *StartOfBuffer,\r
1012 IN UINTN BufferSize,\r
1013 IN CONST CHAR16 *FormatString,\r
1014 IN BASE_LIST Marker\r
1015 )\r
1016{\r
1017 ASSERT_UNICODE_BUFFER (FormatString);\r
1018 return mPrint2SProtocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
1019}\r
1020\r
1021/**\r
1022 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
1023 Unicode format string and variable argument list.\r
1024\r
1025 This function is similar as snprintf_s defined in C11.\r
1026\r
1027 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
1028 and BufferSize.\r
1029 The ASCII string is produced by parsing the format string specified by FormatString.\r
1030 Arguments are pulled from the variable argument list based on the contents of the\r
1031 format string.\r
1032 The number of ASCII characters in the produced output buffer is returned not including\r
1033 the Null-terminator.\r
1034\r
1035 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
1036\r
1037 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r
1038 unmodified and 0 is returned.\r
1039 If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r
1040 unmodified and 0 is returned.\r
1041 If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r
1042 (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r
1043 is unmodified and 0 is returned.\r
1044 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
1045 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
1046 ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r
1047\r
1048 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
1049\r
1050 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
1051 ASCII string.\r
1052 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
1053 @param FormatString A Null-terminated Unicode format string.\r
1054 @param ... Variable argument list whose contents are accessed based on the\r
1055 format string specified by FormatString.\r
1056\r
1057 @return The number of ASCII characters in the produced output buffer not including the\r
1058 Null-terminator.\r
1059\r
1060**/\r
1061UINTN\r
1062EFIAPI\r
1063AsciiSPrintUnicodeFormat (\r
1064 OUT CHAR8 *StartOfBuffer,\r
1065 IN UINTN BufferSize,\r
1066 IN CONST CHAR16 *FormatString,\r
1067 ...\r
1068 )\r
1069{\r
1070 VA_LIST Marker;\r
1071 UINTN NumberOfPrinted;\r
1072\r
1073 VA_START (Marker, FormatString);\r
1074 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
1075 VA_END (Marker);\r
1076 return NumberOfPrinted;\r
1077}\r
1078\r
1079\r
1080#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
1081\r
1082/**\r
1083 [ATTENTION] This function is deprecated for security reason.\r
1084\r
1085 Converts a decimal value to a Null-terminated ASCII string.\r
1086 \r
1087 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
1088 specified by Buffer containing at most Width characters. No padding of spaces \r
1089 is ever performed.\r
1090 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
1091 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
1092 If the conversion contains more than Width characters, then only the first Width\r
1093 characters are returned, and the total number of characters required to perform\r
1094 the conversion is returned.\r
1095 Additional conversion parameters are specified in Flags. \r
1096 The Flags bit LEFT_JUSTIFY is always ignored.\r
1097 All conversions are left justified in Buffer.\r
1098 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
1099 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
1100 are inserted every 3rd digit starting from the right.\r
1101 If RADIX_HEX is set in Flags, then the output buffer will be \r
1102 formatted in hexadecimal format.\r
1103 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
1104 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
1105 then Buffer is padded with '0' characters so the combination of the optional '-' \r
1106 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
1107 add up to Width characters.\r
1108 \r
1109 If Buffer is NULL, then ASSERT().\r
1110 If unsupported bits are set in Flags, then ASSERT().\r
1111 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
1112 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
1113\r
1114 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
1115 ASCII string.\r
1116 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
1117 @param Value The 64-bit signed value to convert to a string.\r
1118 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
1119 the Null-terminator.\r
1120 \r
1121 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
1122\r
1123**/\r
1124UINTN\r
1125EFIAPI\r
1126AsciiValueToString (\r
1127 OUT CHAR8 *Buffer,\r
1128 IN UINTN Flags,\r
1129 IN INT64 Value,\r
1130 IN UINTN Width\r
1131 )\r
1132{\r
1133 RETURN_STATUS Status;\r
1134 UINTN BufferSize;\r
1135\r
1136 if (Width == 0) {\r
1137 BufferSize = (MAXIMUM_VALUE_CHARACTERS + 1) * sizeof (CHAR8);\r
1138 } else {\r
1139 BufferSize = (Width + 1) * sizeof (CHAR8);\r
1140 }\r
1141\r
1142 Status = mPrint2SProtocol->AsciiValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r
1143 if (RETURN_ERROR (Status)) {\r
1144 return 0;\r
1145 }\r
1146\r
1147 return AsciiStrnLenS (Buffer, BufferSize / sizeof (CHAR8));\r
1148}\r
1149\r
1150#endif\r
1151\r
1152/**\r
1153 Converts a decimal value to a Null-terminated Ascii string.\r
1154\r
1155 Converts the decimal number specified by Value to a Null-terminated Ascii\r
1156 string specified by Buffer containing at most Width characters. No padding of\r
1157 spaces is ever performed. If Width is 0 then a width of\r
1158 MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
1159 Width characters, then only the first Width characters are placed in Buffer.\r
1160 Additional conversion parameters are specified in Flags.\r
1161\r
1162 The Flags bit LEFT_JUSTIFY is always ignored.\r
1163 All conversions are left justified in Buffer.\r
1164 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
1165 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
1166 commas are inserted every 3rd digit starting from the right.\r
1167 If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
1168 hexadecimal format.\r
1169 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
1170 Buffer is a '-'.\r
1171 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
1172 Buffer is padded with '0' characters so the combination of the optional '-'\r
1173 sign character, '0' characters, digit characters for Value, and the\r
1174 Null-terminator add up to Width characters.\r
1175\r
1176 If an error would be returned, then the function will ASSERT().\r
1177\r
1178 @param Buffer The pointer to the output buffer for the produced\r
1179 Null-terminated Ascii string.\r
1180 @param BufferSize The size of Buffer in bytes, including the\r
1181 Null-terminator.\r
1182 @param Flags The bitmask of flags that specify left justification,\r
1183 zero pad, and commas.\r
1184 @param Value The 64-bit signed value to convert to a string.\r
1185 @param Width The maximum number of Ascii characters to place in\r
1186 Buffer, not including the Null-terminator.\r
1187\r
1188 @retval RETURN_SUCCESS The decimal value is converted.\r
1189 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r
1190 value.\r
1191 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
1192 If PcdMaximumAsciiStringLength is not\r
1193 zero, and BufferSize is greater than\r
1194 PcdMaximumAsciiStringLength.\r
1195 If unsupported bits are set in Flags.\r
1196 If both COMMA_TYPE and RADIX_HEX are set in\r
1197 Flags.\r
1198 If Width >= MAXIMUM_VALUE_CHARACTERS.\r
1199\r
1200**/\r
1201RETURN_STATUS\r
1202EFIAPI\r
1203AsciiValueToStringS (\r
1204 IN OUT CHAR8 *Buffer,\r
1205 IN UINTN BufferSize,\r
1206 IN UINTN Flags,\r
1207 IN INT64 Value,\r
1208 IN UINTN Width\r
1209 )\r
1210{\r
1211 return mPrint2SProtocol->AsciiValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r
1212}\r
1213\r
1214#define PREFIX_SIGN BIT1\r
1215#define PREFIX_BLANK BIT2\r
1216#define LONG_TYPE BIT4\r
1217#define OUTPUT_UNICODE BIT6\r
1218#define FORMAT_UNICODE BIT8\r
1219#define PAD_TO_WIDTH BIT9\r
1220#define ARGUMENT_UNICODE BIT10\r
1221#define PRECISION BIT11\r
1222#define ARGUMENT_REVERSED BIT12\r
1223#define COUNT_ONLY_NO_PRINT BIT13\r
1224#define UNSIGNED_TYPE BIT14\r
1225\r
1226//\r
1227// Record date and time information\r
1228//\r
1229typedef struct {\r
1230 UINT16 Year;\r
1231 UINT8 Month;\r
1232 UINT8 Day;\r
1233 UINT8 Hour;\r
1234 UINT8 Minute;\r
1235 UINT8 Second;\r
1236 UINT8 Pad1;\r
1237 UINT32 Nanosecond;\r
1238 INT16 TimeZone;\r
1239 UINT8 Daylight;\r
1240 UINT8 Pad2;\r
1241} TIME;\r
1242\r
1243GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
1244\r
1245/**\r
1246 Internal function that convert a number to a string in Buffer.\r
1247\r
1248 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.\r
1249\r
1250 @param Buffer Location to place the ASCII string of Value.\r
1251 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.\r
1252 @param Radix Radix of the value\r
1253\r
1254 @return A pointer to the end of buffer filled with ASCII string.\r
1255\r
1256**/\r
1257CHAR8 *\r
1258InternalPrintLibValueToString (\r
1259 IN OUT CHAR8 *Buffer, \r
1260 IN INT64 Value, \r
1261 IN UINTN Radix\r
1262 )\r
1263{\r
1264 UINT32 Remainder;\r
1265\r
1266 //\r
1267 // Loop to convert one digit at a time in reverse order\r
1268 //\r
1269 *Buffer = 0;\r
1270 do {\r
1271 Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r
1272 *(++Buffer) = mHexStr[Remainder];\r
1273 } while (Value != 0);\r
1274\r
1275 //\r
1276 // Return pointer of the end of filled buffer.\r
1277 //\r
1278 return Buffer;\r
1279}\r
1280\r
1281/**\r
1282 Worker function that produces a Null-terminated string in an output buffer \r
1283 based on a Null-terminated format string and a VA_LIST argument list.\r
1284\r
1285 VSPrint function to process format and place the results in Buffer. Since a \r
1286 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1287 this is the main print working routine.\r
1288\r
1289 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1290\r
1291 @param[out] Buffer The character buffer to print the results of the \r
1292 parsing of Format into.\r
1293 @param[in] BufferSize The maximum number of characters to put into \r
1294 buffer.\r
1295 @param[in] Flags Initial flags value.\r
1296 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1297 and COUNT_ONLY_NO_PRINT set.\r
1298 @param[in] Format A Null-terminated format string.\r
1299 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1300 processing Format.\r
1301 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1302 by processing Format.\r
1303\r
1304 @return The number of characters printed not including the Null-terminator.\r
1305 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1306 modification to Buffer.\r
1307\r
1308**/\r
1309UINTN\r
1310InternalPrintLibSPrintMarker (\r
1311 OUT CHAR8 *Buffer,\r
1312 IN UINTN BufferSize,\r
1313 IN UINTN Flags,\r
1314 IN CONST CHAR8 *Format,\r
1315 IN VA_LIST VaListMarker, OPTIONAL\r
1316 IN BASE_LIST BaseListMarker OPTIONAL\r
1317 );\r
1318\r
1319/**\r
1320 Worker function that produces a Null-terminated string in an output buffer \r
1321 based on a Null-terminated format string and variable argument list.\r
1322\r
1323 VSPrint function to process format and place the results in Buffer. Since a \r
1324 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1325 this is the main print working routine\r
1326\r
1327 @param StartOfBuffer The character buffer to print the results of the parsing\r
1328 of Format into.\r
1329 @param BufferSize The maximum number of characters to put into buffer.\r
1330 Zero means no limit.\r
1331 @param Flags Initial flags value.\r
1332 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
1333 @param FormatString A Null-terminated format string.\r
1334 @param ... The variable argument list.\r
1335\r
1336 @return The number of characters printed.\r
1337\r
1338**/\r
1339UINTN\r
1340EFIAPI\r
1341InternalPrintLibSPrint (\r
1342 OUT CHAR8 *StartOfBuffer,\r
1343 IN UINTN BufferSize,\r
1344 IN UINTN Flags,\r
1345 IN CONST CHAR8 *FormatString,\r
1346 ...\r
1347 )\r
1348{\r
1349 VA_LIST Marker;\r
1350 UINTN NumberOfPrinted;\r
1351\r
1352 VA_START (Marker, FormatString);\r
1353 NumberOfPrinted = InternalPrintLibSPrintMarker (StartOfBuffer, BufferSize, Flags, FormatString, Marker, NULL);\r
1354 VA_END (Marker);\r
1355 return NumberOfPrinted;\r
1356}\r
1357\r
1358#define WARNING_STATUS_NUMBER 5\r
1359#define ERROR_STATUS_NUMBER 33\r
1360\r
1361GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] = {\r
1362 "Success", // RETURN_SUCCESS = 0\r
1363 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1\r
1364 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2\r
1365 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3\r
1366 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4\r
1367 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5\r
1368 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT\r
1369 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT\r
1370 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT\r
1371 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT\r
1372 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT\r
1373 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT\r
1374 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT\r
1375 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT\r
1376 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT\r
1377 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT\r
1378 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT\r
1379 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT\r
1380 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT\r
1381 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT\r
1382 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT\r
1383 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT\r
1384 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT\r
1385 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT\r
1386 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT\r
1387 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT\r
1388 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT\r
1389 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT\r
1390 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT\r
1391 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT\r
1392 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT\r
1393 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT\r
1394 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT\r
1395 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT\r
1396 "Reserved (29)", // RESERVED = 29 | MAX_BIT\r
1397 "Reserved (30)", // RESERVED = 30 | MAX_BIT\r
1398 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT\r
1399 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT\r
1400 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT\r
1401};\r
1402\r
1403/**\r
1404 Internal function that places the character into the Buffer.\r
1405\r
1406 Internal function that places ASCII or Unicode character into the Buffer.\r
1407\r
1408 @param Buffer The buffer to place the Unicode or ASCII string.\r
1409 @param EndBuffer The end of the input Buffer. No characters will be\r
1410 placed after that. \r
1411 @param Length The count of character to be placed into Buffer.\r
1412 (Negative value indicates no buffer fill.)\r
1413 @param Character The character to be placed into Buffer.\r
1414 @param Increment The character increment in Buffer.\r
1415\r
1416 @return Buffer.\r
1417\r
1418**/\r
1419CHAR8 *\r
1420InternalPrintLibFillBuffer (\r
1421 OUT CHAR8 *Buffer,\r
1422 IN CHAR8 *EndBuffer,\r
1423 IN INTN Length,\r
1424 IN UINTN Character,\r
1425 IN INTN Increment\r
1426 )\r
1427{\r
1428 INTN Index;\r
1429 \r
1430 for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {\r
1431 *Buffer = (CHAR8) Character;\r
1432 if (Increment != 1) {\r
1433 *(Buffer + 1) = (CHAR8)(Character >> 8);\r
1434 }\r
1435 Buffer += Increment;\r
1436 }\r
1437\r
1438 return Buffer;\r
1439}\r
1440\r
1441/**\r
1442 Worker function that produces a Null-terminated string in an output buffer \r
1443 based on a Null-terminated format string and a VA_LIST argument list.\r
1444\r
1445 VSPrint function to process format and place the results in Buffer. Since a \r
1446 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1447 this is the main print working routine.\r
1448\r
1449 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1450\r
1451 @param[out] Buffer The character buffer to print the results of the \r
1452 parsing of Format into.\r
1453 @param[in] BufferSize The maximum number of characters to put into \r
1454 buffer.\r
1455 @param[in] Flags Initial flags value.\r
1456 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1457 and COUNT_ONLY_NO_PRINT set.\r
1458 @param[in] Format A Null-terminated format string.\r
1459 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1460 processing Format.\r
1461 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1462 by processing Format.\r
1463\r
1464 @return The number of characters printed not including the Null-terminator.\r
1465 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1466 modification to Buffer.\r
1467\r
1468**/\r
1469UINTN\r
1470InternalPrintLibSPrintMarker (\r
1471 OUT CHAR8 *Buffer,\r
1472 IN UINTN BufferSize,\r
1473 IN UINTN Flags,\r
1474 IN CONST CHAR8 *Format,\r
1475 IN VA_LIST VaListMarker, OPTIONAL\r
1476 IN BASE_LIST BaseListMarker OPTIONAL\r
1477 )\r
1478{\r
1479 CHAR8 *OriginalBuffer;\r
1480 CHAR8 *EndBuffer;\r
1481 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
1482 UINT32 BytesPerOutputCharacter;\r
1483 UINTN BytesPerFormatCharacter;\r
1484 UINTN FormatMask;\r
1485 UINTN FormatCharacter;\r
1486 UINTN Width;\r
1487 UINTN Precision;\r
1488 INT64 Value;\r
1489 CONST CHAR8 *ArgumentString;\r
1490 UINTN Character;\r
1491 GUID *TmpGuid;\r
1492 TIME *TmpTime;\r
1493 UINTN Count;\r
1494 UINTN ArgumentMask;\r
1495 INTN BytesPerArgumentCharacter;\r
1496 UINTN ArgumentCharacter;\r
1497 BOOLEAN Done;\r
1498 UINTN Index;\r
1499 CHAR8 Prefix;\r
1500 BOOLEAN ZeroPad;\r
1501 BOOLEAN Comma;\r
1502 UINTN Digits;\r
1503 UINTN Radix;\r
1504 RETURN_STATUS Status;\r
1505 UINT32 GuidData1;\r
1506 UINT16 GuidData2;\r
1507 UINT16 GuidData3;\r
1508 UINTN LengthToReturn;\r
1509\r
1510 //\r
1511 // If you change this code be sure to match the 2 versions of this function.\r
1512 // Nearly identical logic is found in the BasePrintLib and \r
1513 // DxePrintLibPrint2Protocol (both PrintLib instances).\r
1514 //\r
1515\r
1516 //\r
1517 // 1. Buffer shall not be a null pointer when both BufferSize > 0 and\r
1518 // COUNT_ONLY_NO_PRINT is not set in Flags.\r
1519 //\r
1520 if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) == 0)) {\r
1521 SAFE_PRINT_CONSTRAINT_CHECK ((Buffer != NULL), 0);\r
1522 }\r
1523\r
1524 //\r
1525 // 2. Format shall not be a null pointer when BufferSize > 0 or when\r
1526 // COUNT_ONLY_NO_PRINT is set in Flags.\r
1527 //\r
1528 if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) != 0)) {\r
1529 SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), 0);\r
1530 }\r
1531\r
1532 //\r
1533 // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output or\r
1534 // ASCII_RSIZE_MAX for Ascii output.\r
1535 //\r
1536 if ((Flags & OUTPUT_UNICODE) != 0) {\r
1537 if (RSIZE_MAX != 0) {\r
1538 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= RSIZE_MAX), 0);\r
1539 }\r
1540 BytesPerOutputCharacter = 2;\r
1541 } else {\r
1542 if (ASCII_RSIZE_MAX != 0) {\r
1543 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= ASCII_RSIZE_MAX), 0);\r
1544 }\r
1545 BytesPerOutputCharacter = 1;\r
1546 }\r
1547\r
1548 //\r
1549 // 4. Format shall not contain more than RSIZE_MAX Unicode characters or\r
1550 // ASCII_RSIZE_MAX Ascii characters.\r
1551 //\r
1552 if ((Flags & FORMAT_UNICODE) != 0) {\r
1553 if (RSIZE_MAX != 0) {\r
1554 SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), 0);\r
1555 }\r
1556 BytesPerFormatCharacter = 2;\r
1557 FormatMask = 0xffff;\r
1558 } else {\r
1559 if (ASCII_RSIZE_MAX != 0) {\r
1560 SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), 0);\r
1561 }\r
1562 BytesPerFormatCharacter = 1;\r
1563 FormatMask = 0xff;\r
1564 }\r
1565\r
1566 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r
1567 if (BufferSize == 0) {\r
1568 Buffer = NULL;\r
1569 }\r
1570 } else {\r
1571 //\r
1572 // We can run without a Buffer for counting only.\r
1573 //\r
1574 if (BufferSize == 0) {\r
1575 return 0;\r
1576 }\r
1577 }\r
1578\r
1579 LengthToReturn = 0;\r
1580 EndBuffer = NULL;\r
1581 OriginalBuffer = NULL;\r
1582\r
1583 //\r
1584 // Reserve space for the Null terminator.\r
1585 //\r
1586 if (Buffer != NULL) {\r
1587 BufferSize--;\r
1588 OriginalBuffer = Buffer;\r
1589\r
1590 //\r
1591 // Set the tag for the end of the input Buffer.\r
1592 //\r
1593 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r
1594 }\r
1595\r
1596 //\r
1597 // Get the first character from the format string\r
1598 //\r
1599 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
1600\r
1601 //\r
1602 // Loop until the end of the format string is reached or the output buffer is full\r
1603 //\r
1604 while (FormatCharacter != 0) {\r
1605 if ((Buffer != NULL) && (Buffer >= EndBuffer)) {\r
1606 break;\r
1607 }\r
1608 //\r
1609 // Clear all the flag bits except those that may have been passed in\r
1610 //\r
1611 Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);\r
1612\r
1613 //\r
1614 // Set the default width to zero, and the default precision to 1\r
1615 //\r
1616 Width = 0;\r
1617 Precision = 1;\r
1618 Prefix = 0;\r
1619 Comma = FALSE;\r
1620 ZeroPad = FALSE;\r
1621 Count = 0;\r
1622 Digits = 0;\r
1623\r
1624 switch (FormatCharacter) {\r
1625 case '%':\r
1626 //\r
1627 // Parse Flags and Width\r
1628 //\r
1629 for (Done = FALSE; !Done; ) {\r
1630 Format += BytesPerFormatCharacter;\r
1631 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
1632 switch (FormatCharacter) {\r
1633 case '.': \r
1634 Flags |= PRECISION; \r
1635 break;\r
1636 case '-': \r
1637 Flags |= LEFT_JUSTIFY; \r
1638 break;\r
1639 case '+': \r
1640 Flags |= PREFIX_SIGN; \r
1641 break;\r
1642 case ' ': \r
1643 Flags |= PREFIX_BLANK; \r
1644 break;\r
1645 case ',': \r
1646 Flags |= COMMA_TYPE; \r
1647 break;\r
1648 case 'L':\r
1649 case 'l': \r
1650 Flags |= LONG_TYPE; \r
1651 break;\r
1652 case '*':\r
1653 if ((Flags & PRECISION) == 0) {\r
1654 Flags |= PAD_TO_WIDTH;\r
1655 if (BaseListMarker == NULL) {\r
1656 Width = VA_ARG (VaListMarker, UINTN);\r
1657 } else {\r
1658 Width = BASE_ARG (BaseListMarker, UINTN);\r
1659 }\r
1660 } else {\r
1661 if (BaseListMarker == NULL) {\r
1662 Precision = VA_ARG (VaListMarker, UINTN);\r
1663 } else {\r
1664 Precision = BASE_ARG (BaseListMarker, UINTN);\r
1665 }\r
1666 }\r
1667 break;\r
1668 case '0':\r
1669 if ((Flags & PRECISION) == 0) {\r
1670 Flags |= PREFIX_ZERO;\r
1671 }\r
1672 case '1':\r
1673 case '2':\r
1674 case '3':\r
1675 case '4':\r
1676 case '5':\r
1677 case '6':\r
1678 case '7':\r
1679 case '8':\r
1680 case '9':\r
1681 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){\r
1682 Count = (Count * 10) + FormatCharacter - '0';\r
1683 Format += BytesPerFormatCharacter;\r
1684 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
1685 }\r
1686 Format -= BytesPerFormatCharacter;\r
1687 if ((Flags & PRECISION) == 0) {\r
1688 Flags |= PAD_TO_WIDTH;\r
1689 Width = Count;\r
1690 } else {\r
1691 Precision = Count;\r
1692 }\r
1693 break;\r
1694 \r
1695 case '\0':\r
1696 //\r
1697 // Make no output if Format string terminates unexpectedly when\r
1698 // looking up for flag, width, precision and type. \r
1699 //\r
1700 Format -= BytesPerFormatCharacter;\r
1701 Precision = 0;\r
1702 //\r
1703 // break skipped on purpose.\r
1704 //\r
1705 default:\r
1706 Done = TRUE;\r
1707 break;\r
1708 }\r
1709 } \r
1710\r
1711 //\r
1712 // Handle each argument type\r
1713 //\r
1714 switch (FormatCharacter) {\r
1715 case 'p':\r
1716 //\r
1717 // Flag space, +, 0, L & l are invalid for type p.\r
1718 //\r
1719 Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));\r
1720 if (sizeof (VOID *) > 4) {\r
1721 Flags |= LONG_TYPE;\r
1722 }\r
1723 //\r
1724 // break skipped on purpose\r
1725 //\r
1726 case 'X':\r
1727 Flags |= PREFIX_ZERO;\r
1728 //\r
1729 // break skipped on purpose\r
1730 //\r
1731 case 'x':\r
1732 Flags |= RADIX_HEX;\r
1733 //\r
1734 // break skipped on purpose\r
1735 //\r
1736 case 'u':\r
1737 if ((Flags & RADIX_HEX) == 0) {\r
1738 Flags &= ~((UINTN) (PREFIX_SIGN));\r
1739 Flags |= UNSIGNED_TYPE;\r
1740 }\r
1741 //\r
1742 // break skipped on purpose\r
1743 //\r
1744 case 'd':\r
1745 if ((Flags & LONG_TYPE) == 0) {\r
1746 //\r
1747 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1748 // This assumption is made so the format string definition is compatible with the ANSI C\r
1749 // Specification for formatted strings. It is recommended that the Base Types be used \r
1750 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1751 // provides an implementation that is compatible with that largest possible set of CPU \r
1752 // architectures. This is why the type "int" is used in this one case.\r
1753 //\r
1754 if (BaseListMarker == NULL) {\r
1755 Value = VA_ARG (VaListMarker, int);\r
1756 } else {\r
1757 Value = BASE_ARG (BaseListMarker, int);\r
1758 }\r
1759 } else {\r
1760 if (BaseListMarker == NULL) {\r
1761 Value = VA_ARG (VaListMarker, INT64);\r
1762 } else {\r
1763 Value = BASE_ARG (BaseListMarker, INT64);\r
1764 }\r
1765 }\r
1766 if ((Flags & PREFIX_BLANK) != 0) {\r
1767 Prefix = ' ';\r
1768 }\r
1769 if ((Flags & PREFIX_SIGN) != 0) {\r
1770 Prefix = '+';\r
1771 }\r
1772 if ((Flags & COMMA_TYPE) != 0) {\r
1773 Comma = TRUE;\r
1774 }\r
1775 if ((Flags & RADIX_HEX) == 0) {\r
1776 Radix = 10;\r
1777 if (Comma) {\r
1778 Flags &= ~((UINTN) PREFIX_ZERO);\r
1779 Precision = 1;\r
1780 }\r
1781 if (Value < 0 && (Flags & UNSIGNED_TYPE) == 0) {\r
1782 Flags |= PREFIX_SIGN;\r
1783 Prefix = '-';\r
1784 Value = -Value;\r
1785 } else if ((Flags & UNSIGNED_TYPE) != 0 && (Flags & LONG_TYPE) == 0) {\r
1786 //\r
1787 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1788 // This assumption is made so the format string definition is compatible with the ANSI C\r
1789 // Specification for formatted strings. It is recommended that the Base Types be used \r
1790 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1791 // provides an implementation that is compatible with that largest possible set of CPU \r
1792 // architectures. This is why the type "unsigned int" is used in this one case.\r
1793 //\r
1794 Value = (unsigned int)Value;\r
1795 }\r
1796 } else {\r
1797 Radix = 16;\r
1798 Comma = FALSE;\r
1799 if ((Flags & LONG_TYPE) == 0 && Value < 0) {\r
1800 //\r
1801 // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1802 // This assumption is made so the format string definition is compatible with the ANSI C\r
1803 // Specification for formatted strings. It is recommended that the Base Types be used \r
1804 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1805 // provides an implementation that is compatible with that largest possible set of CPU \r
1806 // architectures. This is why the type "unsigned int" is used in this one case.\r
1807 //\r
1808 Value = (unsigned int)Value;\r
1809 }\r
1810 }\r
1811 //\r
1812 // Convert Value to a reversed string\r
1813 //\r
1814 Count = InternalPrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;\r
1815 if (Value == 0 && Precision == 0) {\r
1816 Count = 0;\r
1817 }\r
1818 ArgumentString = (CHAR8 *)ValueBuffer + Count;\r
1819 \r
1820 Digits = Count % 3;\r
1821 if (Digits != 0) {\r
1822 Digits = 3 - Digits;\r
1823 }\r
1824 if (Comma && Count != 0) {\r
1825 Count += ((Count - 1) / 3);\r
1826 }\r
1827 if (Prefix != 0) {\r
1828 Count++;\r
1829 Precision++;\r
1830 }\r
1831 Flags |= ARGUMENT_REVERSED;\r
1832 ZeroPad = TRUE;\r
1833 if ((Flags & PREFIX_ZERO) != 0) {\r
1834 if ((Flags & LEFT_JUSTIFY) == 0) {\r
1835 if ((Flags & PAD_TO_WIDTH) != 0) {\r
1836 if ((Flags & PRECISION) == 0) {\r
1837 Precision = Width;\r
1838 }\r
1839 }\r
1840 }\r
1841 }\r
1842 break;\r
1843\r
1844 case 's':\r
1845 case 'S':\r
1846 Flags |= ARGUMENT_UNICODE;\r
1847 //\r
1848 // break skipped on purpose\r
1849 //\r
1850 case 'a':\r
1851 if (BaseListMarker == NULL) {\r
1852 ArgumentString = VA_ARG (VaListMarker, CHAR8 *);\r
1853 } else {\r
1854 ArgumentString = BASE_ARG (BaseListMarker, CHAR8 *);\r
1855 }\r
1856 if (ArgumentString == NULL) {\r
1857 Flags &= (~(UINTN)ARGUMENT_UNICODE);\r
1858 ArgumentString = "<null string>";\r
1859 }\r
1860 //\r
1861 // Set the default precision for string to be zero if not specified.\r
1862 //\r
1863 if ((Flags & PRECISION) == 0) {\r
1864 Precision = 0;\r
1865 }\r
1866 break;\r
1867\r
1868 case 'c':\r
1869 if (BaseListMarker == NULL) {\r
1870 Character = VA_ARG (VaListMarker, UINTN) & 0xffff;\r
1871 } else {\r
1872 Character = BASE_ARG (BaseListMarker, UINTN) & 0xffff;\r
1873 }\r
1874 ArgumentString = (CHAR8 *)&Character;\r
1875 Flags |= ARGUMENT_UNICODE;\r
1876 break;\r
1877\r
1878 case 'g':\r
1879 if (BaseListMarker == NULL) {\r
1880 TmpGuid = VA_ARG (VaListMarker, GUID *);\r
1881 } else {\r
1882 TmpGuid = BASE_ARG (BaseListMarker, GUID *);\r
1883 }\r
1884 if (TmpGuid == NULL) {\r
1885 ArgumentString = "<null guid>";\r
1886 } else {\r
1887 GuidData1 = ReadUnaligned32 (&(TmpGuid->Data1));\r
1888 GuidData2 = ReadUnaligned16 (&(TmpGuid->Data2));\r
1889 GuidData3 = ReadUnaligned16 (&(TmpGuid->Data3));\r
1890 InternalPrintLibSPrint (\r
1891 ValueBuffer,\r
1892 MAXIMUM_VALUE_CHARACTERS, \r
1893 0,\r
1894 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
1895 GuidData1,\r
1896 GuidData2,\r
1897 GuidData3,\r
1898 TmpGuid->Data4[0],\r
1899 TmpGuid->Data4[1],\r
1900 TmpGuid->Data4[2],\r
1901 TmpGuid->Data4[3],\r
1902 TmpGuid->Data4[4],\r
1903 TmpGuid->Data4[5],\r
1904 TmpGuid->Data4[6],\r
1905 TmpGuid->Data4[7]\r
1906 );\r
1907 ArgumentString = ValueBuffer;\r
1908 }\r
1909 break;\r
1910\r
1911 case 't':\r
1912 if (BaseListMarker == NULL) {\r
1913 TmpTime = VA_ARG (VaListMarker, TIME *); \r
1914 } else {\r
1915 TmpTime = BASE_ARG (BaseListMarker, TIME *); \r
1916 }\r
1917 if (TmpTime == NULL) {\r
1918 ArgumentString = "<null time>";\r
1919 } else {\r
1920 InternalPrintLibSPrint (\r
1921 ValueBuffer,\r
1922 MAXIMUM_VALUE_CHARACTERS,\r
1923 0,\r
1924 "%02d/%02d/%04d %02d:%02d",\r
1925 TmpTime->Month,\r
1926 TmpTime->Day,\r
1927 TmpTime->Year,\r
1928 TmpTime->Hour,\r
1929 TmpTime->Minute\r
1930 );\r
1931 ArgumentString = ValueBuffer;\r
1932 }\r
1933 break;\r
1934\r
1935 case 'r':\r
1936 if (BaseListMarker == NULL) {\r
1937 Status = VA_ARG (VaListMarker, RETURN_STATUS);\r
1938 } else {\r
1939 Status = BASE_ARG (BaseListMarker, RETURN_STATUS);\r
1940 }\r
1941 ArgumentString = ValueBuffer;\r
1942 if (RETURN_ERROR (Status)) {\r
1943 //\r
1944 // Clear error bit\r
1945 //\r
1946 Index = Status & ~MAX_BIT;\r
1947 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r
1948 ArgumentString = mStatusString [Index + WARNING_STATUS_NUMBER];\r
1949 }\r
1950 } else {\r
1951 Index = Status;\r
1952 if (Index <= WARNING_STATUS_NUMBER) {\r
1953 ArgumentString = mStatusString [Index];\r
1954 }\r
1955 }\r
1956 if (ArgumentString == ValueBuffer) {\r
1957 InternalPrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);\r
1958 }\r
1959 break;\r
1960\r
1961 case '\r':\r
1962 Format += BytesPerFormatCharacter;\r
1963 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
1964 if (FormatCharacter == '\n') {\r
1965 //\r
1966 // Translate '\r\n' to '\r\n'\r
1967 //\r
1968 ArgumentString = "\r\n";\r
1969 } else {\r
1970 //\r
1971 // Translate '\r' to '\r'\r
1972 //\r
1973 ArgumentString = "\r";\r
1974 Format -= BytesPerFormatCharacter;\r
1975 }\r
1976 break;\r
1977\r
1978 case '\n':\r
1979 //\r
1980 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
1981 //\r
1982 ArgumentString = "\r\n";\r
1983 Format += BytesPerFormatCharacter;\r
1984 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
1985 if (FormatCharacter != '\r') {\r
1986 Format -= BytesPerFormatCharacter;\r
1987 }\r
1988 break;\r
1989\r
1990 case '%':\r
1991 default:\r
1992 //\r
1993 // if the type is '%' or unknown, then print it to the screen\r
1994 //\r
1995 ArgumentString = (CHAR8 *)&FormatCharacter;\r
1996 Flags |= ARGUMENT_UNICODE;\r
1997 break;\r
1998 }\r
1999 break;\r
2000 \r
2001 case '\r':\r
2002 Format += BytesPerFormatCharacter;\r
2003 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
2004 if (FormatCharacter == '\n') {\r
2005 //\r
2006 // Translate '\r\n' to '\r\n'\r
2007 //\r
2008 ArgumentString = "\r\n";\r
2009 } else {\r
2010 //\r
2011 // Translate '\r' to '\r'\r
2012 //\r
2013 ArgumentString = "\r";\r
2014 Format -= BytesPerFormatCharacter;\r
2015 }\r
2016 break;\r
2017\r
2018 case '\n':\r
2019 //\r
2020 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
2021 //\r
2022 ArgumentString = "\r\n";\r
2023 Format += BytesPerFormatCharacter;\r
2024 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
2025 if (FormatCharacter != '\r') {\r
2026 Format -= BytesPerFormatCharacter;\r
2027 }\r
2028 break;\r
2029\r
2030 default:\r
2031 ArgumentString = (CHAR8 *)&FormatCharacter;\r
2032 Flags |= ARGUMENT_UNICODE;\r
2033 break;\r
2034 }\r
2035\r
2036 //\r
2037 // Retrieve the ArgumentString attriubutes\r
2038 //\r
2039 if ((Flags & ARGUMENT_UNICODE) != 0) {\r
2040 ArgumentMask = 0xffff;\r
2041 BytesPerArgumentCharacter = 2;\r
2042 } else {\r
2043 ArgumentMask = 0xff;\r
2044 BytesPerArgumentCharacter = 1;\r
2045 }\r
2046 if ((Flags & ARGUMENT_REVERSED) != 0) {\r
2047 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;\r
2048 } else {\r
2049 //\r
2050 // Compute the number of characters in ArgumentString and store it in Count\r
2051 // ArgumentString is either null-terminated, or it contains Precision characters\r
2052 //\r
2053 for (Count = 0;\r
2054 ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&\r
2055 (Count < Precision || ((Flags & PRECISION) == 0));\r
2056 Count++) {\r
2057 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r
2058 if (ArgumentCharacter == 0) {\r
2059 break;\r
2060 }\r
2061 }\r
2062 }\r
2063\r
2064 if (Precision < Count) {\r
2065 Precision = Count;\r
2066 }\r
2067\r
2068 //\r
2069 // Pad before the string\r
2070 //\r
2071 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
2072 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
2073 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2074 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
2075 }\r
2076 }\r
2077\r
2078 if (ZeroPad) {\r
2079 if (Prefix != 0) {\r
2080 LengthToReturn += (1 * BytesPerOutputCharacter);\r
2081 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2082 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
2083 }\r
2084 }\r
2085 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
2086 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2087 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r
2088 }\r
2089 } else {\r
2090 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
2091 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2092 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
2093 }\r
2094 if (Prefix != 0) {\r
2095 LengthToReturn += (1 * BytesPerOutputCharacter);\r
2096 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2097 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
2098 }\r
2099 }\r
2100 }\r
2101\r
2102 //\r
2103 // Output the Prefix character if it is present\r
2104 //\r
2105 Index = 0;\r
2106 if (Prefix != 0) {\r
2107 Index++;\r
2108 }\r
2109\r
2110 //\r
2111 // Copy the string into the output buffer performing the required type conversions\r
2112 //\r
2113 while (Index < Count && (*ArgumentString) != '\0') {\r
2114 ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;\r
2115\r
2116 LengthToReturn += (1 * BytesPerOutputCharacter);\r
2117 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2118 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
2119 }\r
2120 ArgumentString += BytesPerArgumentCharacter;\r
2121 Index++;\r
2122 if (Comma) {\r
2123 Digits++;\r
2124 if (Digits == 3) {\r
2125 Digits = 0;\r
2126 Index++;\r
2127 if (Index < Count) {\r
2128 LengthToReturn += (1 * BytesPerOutputCharacter);\r
2129 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2130 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r
2131 }\r
2132 }\r
2133 }\r
2134 }\r
2135 }\r
2136\r
2137 //\r
2138 // Pad after the string\r
2139 //\r
2140 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
2141 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
2142 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
2143 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
2144 }\r
2145 }\r
2146\r
2147 //\r
2148 // Get the next character from the format string\r
2149 //\r
2150 Format += BytesPerFormatCharacter;\r
2151\r
2152 //\r
2153 // Get the next character from the format string\r
2154 //\r
2155 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r
2156 }\r
2157\r
2158 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r
2159 return (LengthToReturn / BytesPerOutputCharacter);\r
2160 }\r
2161\r
2162 ASSERT (Buffer != NULL);\r
2163 //\r
2164 // Null terminate the Unicode or ASCII string\r
2165 //\r
2166 InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);\r
2167\r
2168 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r
2169}\r
2170\r
2171/**\r
2172 Returns the number of characters that would be produced by if the formatted \r
2173 output were produced not including the Null-terminator.\r
2174\r
2175 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
2176\r
2177 If FormatString is NULL, then ASSERT() and 0 is returned.\r
2178 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more\r
2179 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
2180 Null-terminator, then ASSERT() and 0 is returned.\r
2181\r
2182 @param[in] FormatString A Null-terminated Unicode format string.\r
2183 @param[in] Marker VA_LIST marker for the variable argument list.\r
2184\r
2185 @return The number of characters that would be produced, not including the \r
2186 Null-terminator.\r
2187**/\r
2188UINTN\r
2189EFIAPI\r
2190SPrintLength (\r
2191 IN CONST CHAR16 *FormatString,\r
2192 IN VA_LIST Marker\r
2193 )\r
2194{\r
2195 ASSERT_UNICODE_BUFFER (FormatString);\r
2196 return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
2197}\r
2198\r
2199/**\r
2200 Returns the number of characters that would be produced by if the formatted \r
2201 output were produced not including the Null-terminator.\r
2202\r
2203 If FormatString is NULL, then ASSERT() and 0 is returned.\r
2204 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more\r
2205 than PcdMaximumAsciiStringLength Ascii characters not including the\r
2206 Null-terminator, then ASSERT() and 0 is returned.\r
2207\r
2208 @param[in] FormatString A Null-terminated ASCII format string.\r
2209 @param[in] Marker VA_LIST marker for the variable argument list.\r
2210\r
2211 @return The number of characters that would be produced, not including the \r
2212 Null-terminator.\r
2213**/\r
2214UINTN\r
2215EFIAPI\r
2216SPrintLengthAsciiFormat (\r
2217 IN CONST CHAR8 *FormatString,\r
2218 IN VA_LIST Marker\r
2219 )\r
2220{\r
2221 return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
2222}\r