aboutsummaryrefslogtreecommitdiff
path: root/driver-ti.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 17:00:09 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 17:00:09 +0000
commit052738b8f422060a09a7f5eaadc6b1c19fbcc61d (patch)
tree7ef068da40ac40593cbfb4c949378324b8cd4e5f /driver-ti.c
parent8d2fa34a524f0456e863a22568d6609dcb9ce82a (diff)
downloadtermo-052738b8f422060a09a7f5eaadc6b1c19fbcc61d.tar.gz
termo-052738b8f422060a09a7f5eaadc6b1c19fbcc61d.tar.xz
termo-052738b8f422060a09a7f5eaadc6b1c19fbcc61d.zip
Allow {start,stop}_driver to fail, abort constructor, have driver-ti try to write the entire start/stop string or error out on -1
Diffstat (limited to 'driver-ti.c')
-rw-r--r--driver-ti.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/driver-ti.c b/driver-ti.c
index cbf4a13..af46769 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -289,27 +289,54 @@ abort_free_ti:
return NULL;
}
-static void start_driver(TermKey *tk, void *info)
+static int start_driver(TermKey *tk, void *info)
{
TermKeyTI *ti = info;
+ char *start_string = ti->start_string;
+ size_t len;
+
+ if(tk->fd == -1 || !start_string)
+ return 1;
/* The terminfo database will contain keys in application cursor key mode.
* We may need to enable that mode
*/
- if(tk->fd != -1 && ti->start_string) {
- // Can't call putp or tputs because they suck and don't give us fd control
- (void)write(tk->fd, ti->start_string, strlen(ti->start_string));
+
+ // Can't call putp or tputs because they suck and don't give us fd control
+ len = strlen(start_string);
+ while(len) {
+ size_t written = write(tk->fd, start_string, len);
+ if(written == -1)
+ return 0;
+ start_string += written;
+ len -= written;
}
+ return 1;
}
-static void stop_driver(TermKey *tk, void *info)
+static int stop_driver(TermKey *tk, void *info)
{
TermKeyTI *ti = info;
+ char *stop_string = ti->stop_string;
+ size_t len;
+
+ if(tk->fd == -1 || !stop_string)
+ return 1;
- if(tk->fd != -1 && ti->stop_string) {
- // Can't call putp or tputs because they suck and don't give us fd control
- (void)write(tk->fd, ti->stop_string, strlen(ti->stop_string));
+ /* The terminfo database will contain keys in application cursor key mode.
+ * We may need to enable that mode
+ */
+
+ // Can't call putp or tputs because they suck and don't give us fd control
+ len = strlen(stop_string);
+ while(len) {
+ size_t written = write(tk->fd, stop_string, len);
+ if(written == -1)
+ return 0;
+ stop_string += written;
+ len -= written;
}
+ return 1;
}
static void free_driver(void *info)