From a0a8dccd513f72994414c15648f2b34195f696bb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Wed, 20 Jul 2022 13:11:11 +0200 Subject: [PATCH] Do not return false read error when piping to tio --- src/tty.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tty.c b/src/tty.c index a96c50d..7464d1b 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1153,11 +1153,16 @@ int tty_connect(void) { /* Input from stdin ready */ ssize_t bytes_read = read(STDIN_FILENO, input_buffer, BUFSIZ); - if (bytes_read <= 0) + if (bytes_read < 0) { - tio_error_printf_silent("Could not read from stdin"); + tio_error_printf_silent("Could not read from stdin (%s)", strerror(errno)); goto error_read; } + else if (bytes_read == 0) + { + // Reached EOF (when piping to stdin) + exit(EXIT_SUCCESS); + } /* Process input byte by byte */ for (int i=0; i