Have getkey/waitkey return RES_ERROR/EINVAL if stopped

This commit is contained in:
Paul LeoNerd Evans 2012-03-08 21:31:16 +00:00
parent cb00476f09
commit 8237f3a1bc
2 changed files with 12 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "../termkey.h" #include "../termkey.h"
#include "taplib.h" #include "taplib.h"
@ -8,7 +9,7 @@ int main(int argc, char *argv[])
TermKey *tk; TermKey *tk;
TermKeyKey key; TermKeyKey key;
plan_tests(19); plan_tests(21);
/* We'll need a real filehandle we can write/read. /* We'll need a real filehandle we can write/read.
* pipe() can make us one */ * 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"); 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); termkey_destroy(tk);
return exit_status(); return exit_status();

View File

@ -733,6 +733,11 @@ static TermKeyResult peekkey(TermKey *tk, TermKeyKey *key, int force, size_t *nb
{ {
int again = 0; int again = 0;
if(!tk->is_started) {
errno = EINVAL;
return TERMKEY_RES_ERROR;
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "getkey(force=%d): buffer ", force); fprintf(stderr, "getkey(force=%d): buffer ", force);
print_buffer(tk); print_buffer(tk);