diff --git a/drivers/serial/uart_native_pty.c b/drivers/serial/uart_native_pty.c index c4da0450b25..89f5bb3b196 100644 --- a/drivers/serial/uart_native_pty.c +++ b/drivers/serial/uart_native_pty.c @@ -170,13 +170,11 @@ static int np_uart_stdin_poll_in(const struct device *dev, unsigned char *p_char return -1; } - rc = np_uart_stdin_poll_in_bottom(in_f, p_char); + rc = np_uart_stdin_poll_in_bottom(in_f, p_char, 1); if (rc == -2) { disconnected = true; - return -1; } - - return rc; + return rc == 1 ? 0 : -1; } /** diff --git a/drivers/serial/uart_native_pty_bottom.c b/drivers/serial/uart_native_pty_bottom.c index 0c5546cdeda..3ff7ca59479 100644 --- a/drivers/serial/uart_native_pty_bottom.c +++ b/drivers/serial/uart_native_pty_bottom.c @@ -32,12 +32,13 @@ * * @param in_f Input file descriptor * @param p_char Pointer to character. + * @param len Maximum number of characters to read. * - * @retval 0 If a character arrived and was stored in p_char + * @retval >0 Number of characters actually read * @retval -1 If no character was available to read * @retval -2 if the stdin is disconnected */ -int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char) +int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len) { if (feof(stdin)) { /* @@ -64,12 +65,12 @@ int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char) ERROR("%s: Error on select ()\n", __func__); } - n = read(in_f, p_char, 1); + n = read(in_f, p_char, len); if ((n == -1) || (n == 0)) { return -1; } - return 0; + return n; } /** diff --git a/drivers/serial/uart_native_pty_bottom.h b/drivers/serial/uart_native_pty_bottom.h index 5cbf2783795..69af6d3fa8d 100644 --- a/drivers/serial/uart_native_pty_bottom.h +++ b/drivers/serial/uart_native_pty_bottom.h @@ -20,7 +20,7 @@ extern "C" { /* Note: None of these functions are public interfaces. But internal to the native ptty driver */ -int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char); +int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len); int np_uart_slave_connected(int fd); int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd, bool do_auto_attach, bool wait_pts);