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 <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2024-10-31 10:10:56 +01:00
committed by BOT
parent b9253b4e66
commit 5351a83128

View File

@@ -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;