aboutsummaryrefslogtreecommitdiff
path: root/driver-ti.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-23 02:45:42 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-23 03:05:01 +0200
commitc0cc27c55517f9c3db2370819fc6bc81b80f2eee (patch)
treeff7d80f3ae802ce59b120d6d28069f9d64d6ef7c /driver-ti.c
parent75d3388a351f011fc928ab12168818a5c5f5236f (diff)
downloadtermo-c0cc27c55517f9c3db2370819fc6bc81b80f2eee.tar.gz
termo-c0cc27c55517f9c3db2370819fc6bc81b80f2eee.tar.xz
termo-c0cc27c55517f9c3db2370819fc6bc81b80f2eee.zip
Introduce isatty(3)
Diffstat (limited to 'driver-ti.c')
-rw-r--r--driver-ti.c23
1 files 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 <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
/* 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.