From f85727f042f18d42e77336de138fc81663e32899 Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Wed, 25 Jun 2025 21:22:55 +0200 Subject: output: ioctl error handling. --- src/output.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/output.c') diff --git a/src/output.c b/src/output.c index 396f3ef..ec566d6 100644 --- a/src/output.c +++ b/src/output.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "output.h" #include "data_management.h" @@ -33,12 +34,17 @@ void out_print_time_by_option(struct list_node *ptr); inline int fputc_all_cols(char c, FILE *fdout) { struct winsize terminal; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminal); - /* Somehow not always ws_col == 0, instead > 300 characters */ + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminal) == -1) { + if (errno != 25) { + LOGERR("ERROR: ioctl(STDOUT_FILENO, TIOCGWINSZ,...) failed: %s (errno %d)\n", + strerror(errno), errno); + } + terminal.ws_col = 72; + } + DBGTRC("DEBUG: terminal.ws_col = %d / terminal.ws_row = %d\n", terminal.ws_col, terminal.ws_row); + /* Somehow not always ws_col == 0, with optimization compiler flags and executed by watch. */ if (terminal.ws_col == 0) { terminal.ws_col = 72; - } else if (terminal.ws_col > 144) { - terminal.ws_col = 144; } return fputc_width_x(c, terminal.ws_col, fdout); } -- cgit v1.2.3-70-g09d2