diff --git a/MdePkg/Include/Library/PrintLib.h b/MdePkg/Include/Library/PrintLib.h index 207d33c470..9aca725f7f 100644 --- a/MdePkg/Include/Library/PrintLib.h +++ b/MdePkg/Include/Library/PrintLib.h @@ -15,11 +15,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. strings. Many of the output functions use a format string to describe how to format the output of variable arguments. The format string consists of normal text and argument descriptors. There are no restrictions for how the normal - text and argument descriptors can be mixed. A normal text character '\n' must - always be converted to '\n\r'. This does not follow the ANSI C standard for - sprint(). The format of argument descriptors is described below. The ANSI C - standard for sprint() has been followed for some of the format types, and has - not been followed for others. The exceptions are noted below. + text and argument descriptors can be mixed. The following end of line(EOL) + translations must be performed on the contents of the format string: + + - '\\r' is translated to '\\r' + - '\\r\\n' is translated to '\\r\\n' + - '\\n' is translated to '\\r\\n' + - '\\n\\r' is translated to '\\r\\n' + + This does not follow the ANSI C standard for sprint(). The format of argument + descriptors is described below. The ANSI C standard for sprint() has been + followed for some of the format types, and has not been followed for others. + The exceptions are noted below. %[flags][width][.precision]type diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index ef006bbd00..cf5c28e6f7 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -702,8 +702,33 @@ BasePrintLibSPrintMarker ( } break; + case '\r': + Format += BytesPerFormatCharacter; + FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask; + if (FormatCharacter == '\n') { + // + // Translate '\r\n' to '\r\n' + // + ArgumentString = "\r\n"; + } else { + // + // Translate '\r' to '\r' + // + ArgumentString = "\r"; + Format -= BytesPerFormatCharacter; + } + break; + case '\n': - ArgumentString = "\n\r"; + // + // Translate '\n' to '\r\n' and '\n\r' to '\r\n' + // + ArgumentString = "\r\n"; + Format += BytesPerFormatCharacter; + FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask; + if (FormatCharacter != '\r') { + Format -= BytesPerFormatCharacter; + } break; case '%': @@ -717,8 +742,33 @@ BasePrintLibSPrintMarker ( } break; + case '\r': + Format += BytesPerFormatCharacter; + FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask; + if (FormatCharacter == '\n') { + // + // Translate '\r\n' to '\r\n' + // + ArgumentString = "\r\n"; + } else { + // + // Translate '\r' to '\r' + // + ArgumentString = "\r"; + Format -= BytesPerFormatCharacter; + } + break; + case '\n': - ArgumentString = "\n\r"; + // + // Translate '\n' to '\r\n' and '\n\r' to '\r\n' + // + ArgumentString = "\r\n"; + Format += BytesPerFormatCharacter; + FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask; + if (FormatCharacter != '\r') { + Format -= BytesPerFormatCharacter; + } break; default: