diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-25 21:22:55 +0200 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-25 21:22:55 +0200 |
| commit | f85727f042f18d42e77336de138fc81663e32899 (patch) | |
| tree | c593b166f19ade215a6d61a82a40c6cef8628790 | |
| parent | 111f1bb981d6d6ed6f9116dc297d74ad20010401 (diff) | |
| download | dir_monitor-f85727f042f18d42e77336de138fc81663e32899.tar.gz dir_monitor-f85727f042f18d42e77336de138fc81663e32899.tar.bz2 | |
output: ioctl error handling.
| -rw-r--r-- | src/output.c | 14 |
1 files changed, 10 insertions, 4 deletions
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 <ctype.h> #include <time.h> #include <sys/ioctl.h> +#include <errno.h> #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); } |
