From c0cc27c55517f9c3db2370819fc6bc81b80f2eee Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 23 Sep 2014 02:45:42 +0200 Subject: Introduce isatty(3) --- driver-ti.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/driver-ti.c b/driver-ti.c index ce2a820..ee9104a 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -15,8 +15,6 @@ #include #include #include -#include -#include /* To be efficient at lookups, we store the byte sequence => keyinfo mapping * in a trie. This avoids a slow linear search through a flat list of @@ -309,25 +307,16 @@ static int start_driver (termkey_t *tk, void *info) { termkey_ti_t *ti = info; - struct stat statbuf; char *start_string = ti->start_string; size_t len; - if (tk->fd == -1 || !start_string) + if (tk->fd == -1 || !isatty (tk->fd) || !start_string) return 1; /* The terminfo database will contain keys in application cursor key mode. * We may need to enable that mode */ - // FIXME: isatty() should suffice - /* There's no point trying to write() to a pipe */ - if (fstat (tk->fd, &statbuf) == -1) - return 0; - - if (S_ISFIFO (statbuf.st_mode)) - return 1; - // Can't call putp or tputs because they suck and don't give us fd control len = strlen (start_string); while (len) @@ -346,18 +335,10 @@ static int stop_driver (termkey_t *tk, void *info) { termkey_ti_t *ti = info; - struct stat statbuf; char *stop_string = ti->stop_string; size_t len; - if (tk->fd == -1 || !stop_string) - return 1; - - /* There's no point trying to write() to a pipe */ - if (fstat (tk->fd, &statbuf) == -1) - return 0; - - if (S_ISFIFO (statbuf.st_mode)) + if (tk->fd == -1 || !isatty (tk->fd) || !stop_string) return 1; /* The terminfo database will contain keys in application cursor key mode. -- cgit v1.2.3-70-g09d2