diff mbox series

[XTF,v2,v2,2/4] lib: always append CR after LF in vsnprintf()

Message ID 20200423101955.13761-3-wipawel@amazon.de (mailing list archive)
State New, archived
Headers show
Series Small fixes and improvements | expand

Commit Message

Wieczorkiewicz, Pawel April 23, 2020, 10:19 a.m. UTC
The explicit LFCR sequence guarantees proper line by line formatting
in the output.
The '\n' character alone on some terminals is not automatically
converted to LFCR.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
---
Changed since v1:
  * Emit CRLF instead of LFCR

 common/libc/vsnprintf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/common/libc/vsnprintf.c b/common/libc/vsnprintf.c
index a49fd30..b9a4fab 100644
--- a/common/libc/vsnprintf.c
+++ b/common/libc/vsnprintf.c
@@ -284,7 +284,17 @@  int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
         /* Put regular characters into the destination. */
         if ( *fmt != '%' )
         {
+            /*
+             * The '\n' character alone on some terminals is not automatically
+             * converted to CRLF.
+             * The explicit CRLF sequence guarantees proper line by line
+             * formatting in the output.
+             */
+            if ( *fmt == '\n' && str < end )
+                PUT('\r');
+
             PUT(*fmt);
+
             continue;
         }