11#define WARNING_STATUS_NUMBER 7
12#define ERROR_STATUS_NUMBER 35
17#define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength))
18#define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength))
20#define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \
22 ASSERT (Expression); \
23 if (!(Expression)) { \
28GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
35 "Warning Unknown Glyph",
36 "Warning Delete Failure",
37 "Warning Write Failure",
38 "Warning Buffer Too Small",
40 "Warning File System",
41 "Warning Reset Required",
72 "Incompatible Version",
81 "IP Address Conflict",
112 for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {
113 *Buffer = (CHAR8)Character;
114 if (Increment != 1) {
115 *(Buffer + 1) = (CHAR8)(Character >> 8);
138 IN OUT CHAR8 *Buffer,
151 *(++Buffer) = mHexStr[Remainder];
152 }
while (Value != 0);
200 IN OUT CHAR8 *Buffer,
207 CHAR8 *OriginalBuffer;
210 CHAR8 *ValueBufferPtr;
219 ASSERT (Buffer !=
NULL);
224 ASSERT ((Flags & ~(
LEFT_JUSTIFY | COMMA_TYPE | PREFIX_ZERO | RADIX_HEX)) == 0);
229 ASSERT (((Flags & COMMA_TYPE) == 0) || ((Flags & RADIX_HEX) == 0));
231 OriginalBuffer = Buffer;
236 if ((Width == 0) || ((Flags & COMMA_TYPE) != 0)) {
237 Flags &= ~((
UINTN)PREFIX_ZERO);
250 EndBuffer = Buffer + Width * Increment;
255 if ((Value < 0) && ((Flags & RADIX_HEX) == 0)) {
264 Radix = ((Flags & RADIX_HEX) == 0) ? 10 : 16;
266 Count = ValueBufferPtr - ValueBuffer;
271 if ((Flags & PREFIX_ZERO) != 0) {
283 for (Index = 0; Index < Count; Index++) {
285 if ((Flags & COMMA_TYPE) != 0) {
289 if ((Index + 1) < Count) {
301 return ((Buffer - OriginalBuffer) / Increment);
357 IN OUT CHAR8 *Buffer,
367 CHAR8 *ValueBufferPtr;
383 if (Increment == 1) {
387 if (ASCII_RSIZE_MAX != 0) {
394 if (RSIZE_MAX != 0) {
403 SAFE_PRINT_CONSTRAINT_CHECK ((((Flags & COMMA_TYPE) == 0) || ((Flags & RADIX_HEX) == 0)),
RETURN_INVALID_PARAMETER);
413 if ((Width == 0) || ((Flags & COMMA_TYPE) != 0)) {
414 Flags &= ~((
UINTN)PREFIX_ZERO);
428 Radix = ((Flags & RADIX_HEX) == 0) ? 10 : 16;
430 if ((Flags & PREFIX_ZERO) != 0) {
433 if ((Value < 0) && ((Flags & RADIX_HEX) == 0)) {
440 Digits = ValueBufferPtr - ValueBuffer;
443 if ((Flags & COMMA_TYPE) != 0) {
444 Count += (Digits - 1) / 3;
448 Width =
MIN (Count, Width);
458 EndBuffer = Buffer + Width * Increment;
463 if ((Value < 0) && ((Flags & RADIX_HEX) == 0)) {
473 Count = ValueBufferPtr - ValueBuffer;
478 if ((Flags & PREFIX_ZERO) != 0) {
490 for (Index = 0; Index < Count; Index++) {
492 if ((Flags & COMMA_TYPE) != 0) {
496 if ((Index + 1) < Count) {
549 CHAR8 *OriginalBuffer;
552 UINT32 BytesPerOutputCharacter;
553 UINTN BytesPerFormatCharacter;
555 UINTN FormatCharacter;
559 CONST CHAR8 *ArgumentString;
565 INTN BytesPerArgumentCharacter;
566 UINTN ArgumentCharacter;
574 RETURN_STATUS Status;
578 UINTN LengthToReturn;
590 if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) == 0)) {
591 SAFE_PRINT_CONSTRAINT_CHECK ((Buffer !=
NULL), 0);
598 if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) != 0)) {
599 SAFE_PRINT_CONSTRAINT_CHECK ((Format !=
NULL), 0);
606 if ((Flags & OUTPUT_UNICODE) != 0) {
607 if (RSIZE_MAX != 0) {
608 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= RSIZE_MAX), 0);
611 BytesPerOutputCharacter = 2;
613 if (ASCII_RSIZE_MAX != 0) {
614 SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= ASCII_RSIZE_MAX), 0);
617 BytesPerOutputCharacter = 1;
624 if ((Flags & FORMAT_UNICODE) != 0) {
625 if (RSIZE_MAX != 0) {
626 SAFE_PRINT_CONSTRAINT_CHECK ((
StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), 0);
629 BytesPerFormatCharacter = 2;
632 if (ASCII_RSIZE_MAX != 0) {
633 SAFE_PRINT_CONSTRAINT_CHECK ((
AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), 0);
636 BytesPerFormatCharacter = 1;
640 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
641 if (BufferSize == 0) {
648 if (BufferSize == 0) {
655 OriginalBuffer =
NULL;
660 if (Buffer !=
NULL) {
662 OriginalBuffer = Buffer;
667 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
673 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
678 while (FormatCharacter != 0) {
679 if ((Buffer !=
NULL) && (Buffer >= EndBuffer)) {
686 Flags &= (
UINTN)(OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
699 switch (FormatCharacter) {
704 for (Done =
FALSE; !Done; ) {
705 Format += BytesPerFormatCharacter;
706 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
707 switch (FormatCharacter) {
715 Flags |= PREFIX_SIGN;
718 Flags |= PREFIX_BLANK;
728 if ((Flags & PRECISION) == 0) {
729 Flags |= PAD_TO_WIDTH;
730 if (BaseListMarker ==
NULL) {
736 if (BaseListMarker ==
NULL) {
745 if ((Flags & PRECISION) == 0) {
746 Flags |= PREFIX_ZERO;
758 for (Count = 0; ((FormatCharacter >=
'0') && (FormatCharacter <=
'9')); ) {
759 Count = (Count * 10) + FormatCharacter -
'0';
760 Format += BytesPerFormatCharacter;
761 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
764 Format -= BytesPerFormatCharacter;
765 if ((Flags & PRECISION) == 0) {
766 Flags |= PAD_TO_WIDTH;
779 Format -= BytesPerFormatCharacter;
793 switch (FormatCharacter) {
798 Flags &= ~((
UINTN)(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));
799 if (
sizeof (VOID *) > 4) {
807 Flags |= PREFIX_ZERO;
817 if ((Flags & RADIX_HEX) == 0) {
818 Flags &= ~((
UINTN)(PREFIX_SIGN));
819 Flags |= UNSIGNED_TYPE;
826 if ((Flags & LONG_TYPE) == 0) {
835 if (BaseListMarker ==
NULL) {
836 Value =
VA_ARG (VaListMarker,
int);
838 Value =
BASE_ARG (BaseListMarker,
int);
841 if (BaseListMarker ==
NULL) {
842 Value =
VA_ARG (VaListMarker, INT64);
844 Value =
BASE_ARG (BaseListMarker, INT64);
848 if ((Flags & PREFIX_BLANK) != 0) {
852 if ((Flags & PREFIX_SIGN) != 0) {
856 if ((Flags & COMMA_TYPE) != 0) {
860 if ((Flags & RADIX_HEX) == 0) {
863 Flags &= ~((
UINTN)PREFIX_ZERO);
867 if ((Value < 0) && ((Flags & UNSIGNED_TYPE) == 0)) {
868 Flags |= PREFIX_SIGN;
871 }
else if (((Flags & UNSIGNED_TYPE) != 0) && ((Flags & LONG_TYPE) == 0)) {
880 Value = (
unsigned int)Value;
885 if (((Flags & LONG_TYPE) == 0) && (Value < 0)) {
894 Value = (
unsigned int)Value;
902 if ((Value == 0) && (Precision == 0)) {
906 ArgumentString = (CHAR8 *)ValueBuffer + Count;
913 if (Comma && (Count != 0)) {
914 Count += ((Count - 1) / 3);
922 Flags |= ARGUMENT_REVERSED;
924 if ((Flags & PREFIX_ZERO) != 0) {
926 if ((Flags & PAD_TO_WIDTH) != 0) {
927 if ((Flags & PRECISION) == 0) {
938 Flags |= ARGUMENT_UNICODE;
943 if (BaseListMarker ==
NULL) {
944 ArgumentString =
VA_ARG (VaListMarker, CHAR8 *);
946 ArgumentString =
BASE_ARG (BaseListMarker, CHAR8 *);
949 if (ArgumentString ==
NULL) {
950 Flags &= ~((
UINTN)ARGUMENT_UNICODE);
951 ArgumentString =
"<null string>";
957 if ((Flags & PRECISION) == 0) {
964 if (BaseListMarker ==
NULL) {
970 ArgumentString = (CHAR8 *)&Character;
971 Flags |= ARGUMENT_UNICODE;
975 if (BaseListMarker ==
NULL) {
981 if (TmpGuid ==
NULL) {
982 ArgumentString =
"<null guid>";
991 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1004 ArgumentString = ValueBuffer;
1010 if (BaseListMarker ==
NULL) {
1016 if (TmpTime ==
NULL) {
1017 ArgumentString =
"<null time>";
1023 "%02d/%02d/%04d %02d:%02d",
1030 ArgumentString = ValueBuffer;
1036 if (BaseListMarker ==
NULL) {
1037 Status =
VA_ARG (VaListMarker, RETURN_STATUS);
1039 Status =
BASE_ARG (BaseListMarker, RETURN_STATUS);
1042 ArgumentString = ValueBuffer;
1047 Index = Status & ~MAX_BIT;
1048 if ((Index > 0) && (Index <= ERROR_STATUS_NUMBER)) {
1049 ArgumentString = mErrorString[Index - 1];
1053 if (Index <= WARNING_STATUS_NUMBER) {
1054 ArgumentString = mWarningString[Index];
1058 if (ArgumentString == ValueBuffer) {
1065 Format += BytesPerFormatCharacter;
1066 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
1067 if (FormatCharacter ==
'\n') {
1071 ArgumentString =
"\r\n";
1076 ArgumentString =
"\r";
1077 Format -= BytesPerFormatCharacter;
1086 ArgumentString =
"\r\n";
1087 Format += BytesPerFormatCharacter;
1088 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
1089 if (FormatCharacter !=
'\r') {
1090 Format -= BytesPerFormatCharacter;
1100 ArgumentString = (CHAR8 *)&FormatCharacter;
1101 Flags |= ARGUMENT_UNICODE;
1108 Format += BytesPerFormatCharacter;
1109 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
1110 if (FormatCharacter ==
'\n') {
1114 ArgumentString =
"\r\n";
1119 ArgumentString =
"\r";
1120 Format -= BytesPerFormatCharacter;
1129 ArgumentString =
"\r\n";
1130 Format += BytesPerFormatCharacter;
1131 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
1132 if (FormatCharacter !=
'\r') {
1133 Format -= BytesPerFormatCharacter;
1139 ArgumentString = (CHAR8 *)&FormatCharacter;
1140 Flags |= ARGUMENT_UNICODE;
1147 if ((Flags & ARGUMENT_UNICODE) != 0) {
1148 ArgumentMask = 0xffff;
1149 BytesPerArgumentCharacter = 2;
1151 ArgumentMask = 0xff;
1152 BytesPerArgumentCharacter = 1;
1155 if ((Flags & ARGUMENT_REVERSED) != 0) {
1156 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
1163 (ArgumentString[Count * BytesPerArgumentCharacter] !=
'\0' ||
1164 (BytesPerArgumentCharacter > 1 &&
1165 ArgumentString[Count * BytesPerArgumentCharacter + 1] !=
'\0')) &&
1166 (Count < Precision || ((Flags & PRECISION) == 0));
1169 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
1170 if (ArgumentCharacter == 0) {
1176 if (Precision < Count) {
1183 if ((Flags & (PAD_TO_WIDTH |
LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
1184 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
1185 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1192 LengthToReturn += (1 * BytesPerOutputCharacter);
1193 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1198 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
1199 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1203 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
1204 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1209 LengthToReturn += (1 * BytesPerOutputCharacter);
1210 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1227 while (Index < Count &&
1228 (ArgumentString[0] !=
'\0' ||
1229 (BytesPerArgumentCharacter > 1 && ArgumentString[1] !=
'\0')))
1231 ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;
1233 LengthToReturn += (1 * BytesPerOutputCharacter);
1234 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1238 ArgumentString += BytesPerArgumentCharacter;
1245 if (Index < Count) {
1246 LengthToReturn += (1 * BytesPerOutputCharacter);
1247 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1259 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
1260 if (((Flags & COUNT_ONLY_NO_PRINT) == 0) && (Buffer !=
NULL)) {
1268 Format += BytesPerFormatCharacter;
1273 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
1276 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
1277 return (LengthToReturn / BytesPerOutputCharacter);
1280 ASSERT (Buffer !=
NULL);
1286 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
1312 OUT CHAR8 *StartOfBuffer,
1320 UINTN NumberOfPrinted;
1325 return NumberOfPrinted;
UINTN EFIAPI AsciiStrnLenS(IN CONST CHAR8 *String, IN UINTN MaxSize)
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
UINTN EFIAPI StrnLenS(IN CONST CHAR16 *String, IN UINTN MaxSize)
UINT64 EFIAPI DivU64x32Remainder(IN UINT64 Dividend, IN UINT32 Divisor, OUT UINT32 *Remainder OPTIONAL)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
#define RETURN_BUFFER_TOO_SMALL
#define RETURN_ERROR(StatusCode)
#define VA_ARG(Marker, TYPE)
#define BASE_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define RETURN_INVALID_PARAMETER
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define MAXIMUM_VALUE_CHARACTERS
CHAR8 * BasePrintLibValueToString(IN OUT CHAR8 *Buffer, IN INT64 Value, IN UINTN Radix)
CHAR8 * BasePrintLibFillBuffer(OUT CHAR8 *Buffer, IN CHAR8 *EndBuffer, IN INTN Length, IN UINTN Character, IN INTN Increment)
UINTN EFIAPI BasePrintLibSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN UINTN Flags, IN CONST CHAR8 *FormatString,...)
RETURN_STATUS BasePrintLibConvertValueToStringS(IN OUT CHAR8 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width, IN UINTN Increment)
UINTN BasePrintLibConvertValueToString(IN OUT CHAR8 *Buffer, IN UINTN Flags, IN INT64 Value, IN UINTN Width, IN UINTN Increment)
UINTN BasePrintLibSPrintMarker(OUT CHAR8 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker OPTIONAL, IN BASE_LIST BaseListMarker OPTIONAL)