mirror of
https://github.com/troglobit/libite.git
synced 2026-10-04 14:34:12 +07:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#define CONIO_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* 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;
|
||||
|
||||
Reference in New Issue
Block a user