aboutsummaryrefslogtreecommitdiff
path: root/driver-ti.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 20:01:11 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 20:01:11 +0000
commit2ed8bae4f603e1086c2a1056c108209893b541ba (patch)
tree48ef56a2a571802c0d51b0f741e49cc153d240fd /driver-ti.c
parent62b8773108bb7d623b279e77494b919b5c9d8568 (diff)
downloadtermo-2ed8bae4f603e1086c2a1056c108209893b541ba.tar.gz
termo-2ed8bae4f603e1086c2a1056c108209893b541ba.tar.xz
termo-2ed8bae4f603e1086c2a1056c108209893b541ba.zip
Don't try to write() the start/stop string if the fd is a pipe, because this will never work
Diffstat (limited to 'driver-ti.c')
-rw-r--r--driver-ti.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/driver-ti.c b/driver-ti.c
index af46769..d827bdf 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -18,6 +18,8 @@
#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
@@ -292,6 +294,7 @@ abort_free_ti:
static int start_driver(TermKey *tk, void *info)
{
TermKeyTI *ti = info;
+ struct stat statbuf;
char *start_string = ti->start_string;
size_t len;
@@ -302,6 +305,13 @@ static int start_driver(TermKey *tk, void *info)
* We may need to enable that mode
*/
+ /* 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) {
@@ -317,12 +327,20 @@ static int start_driver(TermKey *tk, void *info)
static int stop_driver(TermKey *tk, void *info)
{
TermKeyTI *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))
+ return 1;
+
/* The terminfo database will contain keys in application cursor key mode.
* We may need to enable that mode
*/