From ef0db5e7663576c71a11266a7e7ada6c671f249f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 24 Oct 2017 08:28:55 +0200 Subject: [PATCH] initscr(): Check if stdin and stdout are TTYs first Programs that may be called in the background or with the stdin/stdout redirected are not proper TTYs and we should not try to perform any tricks on them. This patch checks isatty() and returns standard term sizes as a fallback. Signed-off-by: Joachim Nilsson --- conio.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conio.h b/conio.h index 983efc8..fef3a9e 100644 --- a/conio.h +++ b/conio.h @@ -19,6 +19,7 @@ #define CONIO_H_ #include +#include /* Attributes */ #define RESETATTR 0 @@ -94,6 +95,12 @@ static inline void initscr(int *row, int *col) struct termios tc, saved; struct pollfd fd = { STDIN_FILENO, POLLIN, 0 }; + if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { + *row = 24; + *col = 80; + return; + } + /* Disable echo to terminal while probing */ tcgetattr(STDERR_FILENO, &tc); saved = tc;