From 5351a8312829be92b9b07bccb683c77036c80c71 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Thu, 31 Oct 2024 10:10:56 +0100 Subject: [PATCH] feat(newlib): change line endings on standard input and output Currently, the newline conversions for the NEWLIB_STDOUT_LINE_ENDING and NEWLIB_STDIN_LINE_ENDING options are only applied by VFS drivers. Without VFS, newline conversion does not occur. Introduce the default conversion of LF to CRLF on stdout and CF to LF on stdin for the default read and write syscalls in newlib. Signed-off-by: Frantisek Hrbata --- components/newlib/syscalls.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/newlib/syscalls.c b/components/newlib/syscalls.c index 20d890b287..c60280912f 100644 --- a/components/newlib/syscalls.c +++ b/components/newlib/syscalls.c @@ -33,6 +33,9 @@ ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t siz const char* cdata = (const char*) data; if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { for (size_t i = 0; i < size; ++i) { + if (cdata[i] == '\n') { + esp_rom_output_tx_one_char('\r'); + } esp_rom_output_tx_one_char(cdata[i]); } return size; @@ -53,6 +56,9 @@ ssize_t _read_r_console(struct _reent *r, int fd, void * data, size_t size) if (status != 0) { break; } + if (cdata[received] == '\r') { + cdata[received] = '\n'; + } } if (received == 0) { errno = EWOULDBLOCK;