diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2012-01-18 14:03:39 +0000 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2012-01-18 14:03:39 +0000 |
commit | 6d6afe788c3ec1f320e12449eee230fb366228c5 (patch) | |
tree | a7f17b111e20dbe67bcaf5067f2ecd9c00d9f1db /termkey.c | |
parent | 82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e (diff) | |
download | termo-6d6afe788c3ec1f320e12449eee230fb366228c5.tar.gz termo-6d6afe788c3ec1f320e12449eee230fb366228c5.tar.xz termo-6d6afe788c3ec1f320e12449eee230fb366228c5.zip |
Allow passing fd = -1 to constructor to make an instance not associated with an fd; must use push_bytes to provide it input
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -284,7 +284,7 @@ static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittim goto abort_free_keynames; } - if(!(flags & TERMKEY_FLAG_NOTERMIOS)) { + if(fd != -1 && !(flags & TERMKEY_FLAG_NOTERMIOS)) { struct termios termios; if(tcgetattr(fd, &termios) == 0) { tk->restore_termios = termios; @@ -887,6 +887,11 @@ TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key) TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key) { + if(tk->fd == -1) { + errno = EBADF; + return TERMKEY_RES_ERROR; + } + while(1) { TermKeyResult ret = termkey_getkey(tk, key); @@ -944,6 +949,11 @@ TermKeyResult termkey_advisereadable(TermKey *tk) { ssize_t len; + if(tk->fd == -1) { + errno = EBADF; + return TERMKEY_RES_ERROR; + } + if(tk->buffstart) { memmove(tk->buffer, tk->buffer + tk->buffstart, tk->buffcount); tk->buffstart = 0; |