diff --git a/src/error.c b/src/error.c index ca5aa18..3bcadde 100644 --- a/src/error.c +++ b/src/error.c @@ -27,10 +27,14 @@ #include "tio/print.h" #include "tio/error.h" -char error[1000]; +char error[2][1000]; void error_exit(void) { - if ((error[0] != 0) && (option.no_autoconnect)) - printf("\rError: %s\r\n", error); + /* Always print errors but only print silent errors when in no autoconnect + * mode */ + if (error[0][0] != 0) + printf("\rError: %s\r\n", error[0]); + else if ((error[1][0] != 0) && (option.no_autoconnect)) + printf("\rError: %s\r\n", error[1]); } diff --git a/src/include/tio/error.h b/src/include/tio/error.h index b770854..d41dcaa 100644 --- a/src/include/tio/error.h +++ b/src/include/tio/error.h @@ -25,10 +25,13 @@ #define TIO_SUCCESS 0 #define TIO_ERROR 1 -extern char error[1000]; +extern char error[2][1000]; #define error_printf(format, args...) \ - snprintf (error, 1000, format, ## args); + snprintf (error[0], 1000, format, ## args); + +#define error_printf_silent(format, args...) \ + snprintf (error[1], 1000, format, ## args); void error_exit(void); diff --git a/src/tty.c b/src/tty.c index 3b9a38f..d042823 100644 --- a/src/tty.c +++ b/src/tty.c @@ -230,14 +230,14 @@ int connect_tty(void) fd = open(option.tty_device, O_RDWR | O_NOCTTY ); if (fd < 0) { - error_printf("Could not open tty device (%s)", strerror(errno)); + error_printf_silent("Could not open tty device (%s)", strerror(errno)); goto error_open; } /* Make sure device is of tty type */ if (!isatty(fd)) { - error_printf("Not a tty device"); + error_printf_silent("Not a tty device"); goto error_isatty; } @@ -315,7 +315,7 @@ int connect_tty(void) } else { /* Error reading - device is likely unplugged */ - error_printf("Could not read from tty device"); + error_printf_silent("Could not read from tty device"); goto error_read; } } @@ -327,7 +327,7 @@ int connect_tty(void) status = read(STDIN_FILENO, &input_char, 1); if (status <= 0) { - error_printf("Could not read from stdin"); + error_printf_silent("Could not read from stdin"); goto error_read; }