From 3b07736b6d4d6c8110e487b0001661f9251b5016 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 21 Mar 2020 17:19:49 -0500 Subject: [PATCH] unix,windows: Use STDIN_FILENO, STDOUT_FILENO macros where appropriate. This replaces 0 and 1 with STDIN_FILENO and STDOUT_FILENO to make the intention of the code clearer. --- ports/minimal/uart_core.c | 4 ++-- ports/unix/unix_mphal.c | 4 ++-- ports/windows/windows_mphal.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/minimal/uart_core.c b/ports/minimal/uart_core.c index 5b3797d2eb..c7af24404b 100644 --- a/ports/minimal/uart_core.c +++ b/ports/minimal/uart_core.c @@ -17,7 +17,7 @@ typedef struct { int mp_hal_stdin_rx_chr(void) { unsigned char c = 0; #if MICROPY_MIN_USE_STDOUT - int r = read(0, &c, 1); + int r = read(STDIN_FILENO, &c, 1); (void)r; #elif MICROPY_MIN_USE_STM32_MCU // wait for RXNE @@ -31,7 +31,7 @@ int mp_hal_stdin_rx_chr(void) { // Send string of given length void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { #if MICROPY_MIN_USE_STDOUT - int r = write(1, str, len); + int r = write(STDOUT_FILENO, str, len); (void)r; #elif MICROPY_MIN_USE_STM32_MCU while (len--) { diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 0d7638f4eb..966d7c0ece 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -167,7 +167,7 @@ main_term:; MP_THREAD_GIL_EXIT(); unsigned char c; - int ret = read(0, &c, 1); + int ret = read(STDIN_FILENO, &c, 1); MP_THREAD_GIL_ENTER(); if (ret == 0) { c = 4; // EOF, ctrl-D @@ -179,7 +179,7 @@ main_term:; void mp_hal_stdout_tx_strn(const char *str, size_t len) { MP_THREAD_GIL_EXIT(); - int ret = write(1, str, len); + int ret = write(STDOUT_FILENO, str, len); MP_THREAD_GIL_ENTER(); mp_uos_dupterm_tx_strn(str, len); (void)ret; // to suppress compiler warning diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 7835c6121c..6ee37fdd27 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -222,7 +222,7 @@ int mp_hal_stdin_rx_chr(void) { void mp_hal_stdout_tx_strn(const char *str, size_t len) { MP_THREAD_GIL_EXIT(); - write(1, str, len); + write(STDOUT_FILENO, str, len); MP_THREAD_GIL_ENTER(); }