From c7b27b022f863c92e1e9abef7b1f4c3c7503f38b Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Tue, 24 May 2022 13:35:27 +0200 Subject: [PATCH] Redirect error messages to stderr --- src/error.c | 4 ++-- src/print.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/error.c b/src/error.c index 96969f7..8e25a8c 100644 --- a/src/error.c +++ b/src/error.c @@ -35,11 +35,11 @@ void error_exit(void) if (error[0][0] != 0) { /* Print error */ - tio_printf("Error: %s", error[0]); + tio_error_printf("Error: %s", error[0]); } else if ((error[1][0] != 0) && (option.no_autoconnect)) { /* Print silent error */ - tio_printf("Error: %s", error[1]); + tio_error_printf("Error: %s", error[1]); } } diff --git a/src/print.h b/src/print.h index 3f8e16e..1c6b1e5 100644 --- a/src/print.h +++ b/src/print.h @@ -36,6 +36,12 @@ extern char ansi_format[]; fflush(stdout); \ } +#define ansi_error_printf(format, args...) \ +{ \ + fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \ + fflush(stderr); \ +} + #define ansi_printf_raw(format, args...) \ { \ fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \ @@ -56,6 +62,14 @@ extern char ansi_format[]; print_tainted = false; \ } +#define tio_error_printf(format, args...) \ +{ \ + if (print_tainted) \ + putchar('\n'); \ + ansi_error_printf("[%s] " format, current_time(), ## args); \ + print_tainted = false; \ +} + #define error_printf(format, args...) \ snprintf(error[0], 1000, format, ## args);