aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-03-08 21:31:16 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-03-08 21:31:16 +0000
commit8237f3a1bc79687e37a6c6bf9ec66fde2eefe29d (patch)
tree3fa07611e567589b1152945e5e528549eee814f6
parentcb00476f09d5ab7e342f562e6c516f23c98aac88 (diff)
downloadtermo-8237f3a1bc79687e37a6c6bf9ec66fde2eefe29d.tar.gz
termo-8237f3a1bc79687e37a6c6bf9ec66fde2eefe29d.tar.xz
termo-8237f3a1bc79687e37a6c6bf9ec66fde2eefe29d.zip
Have getkey/waitkey return RES_ERROR/EINVAL if stopped
-rw-r--r--t/05read.c8
-rw-r--r--termkey.c5
2 files changed, 12 insertions, 1 deletions
diff --git a/t/05read.c b/t/05read.c
index da87a5e..0353abb 100644
--- a/t/05read.c
+++ b/t/05read.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <errno.h>
#include "../termkey.h"
#include "taplib.h"
@@ -8,7 +9,7 @@ int main(int argc, char *argv[])
TermKey *tk;
TermKeyKey key;
- plan_tests(19);
+ plan_tests(21);
/* We'll need a real filehandle we can write/read.
* pipe() can make us one */
@@ -60,6 +61,11 @@ int main(int argc, char *argv[])
is_int(termkey_get_buffer_remaining(tk), 256, "buffer free 256 after completion");
+ termkey_stop(tk);
+
+ is_int(termkey_getkey(tk, &key), TERMKEY_RES_ERROR, "getkey yields RES_ERROR after termkey_stop()");
+ is_int(errno, EINVAL, "getkey error is EINVAL");
+
termkey_destroy(tk);
return exit_status();
diff --git a/termkey.c b/termkey.c
index 5f5a9a9..163e168 100644
--- a/termkey.c
+++ b/termkey.c
@@ -733,6 +733,11 @@ static TermKeyResult peekkey(TermKey *tk, TermKeyKey *key, int force, size_t *nb
{
int again = 0;
+ if(!tk->is_started) {
+ errno = EINVAL;
+ return TERMKEY_RES_ERROR;
+ }
+
#ifdef DEBUG
fprintf(stderr, "getkey(force=%d): buffer ", force);
print_buffer(tk);