Cope correctly with EOF

This commit is contained in:
Paul LeoNerd Evans 2008-02-09 19:01:49 +00:00
parent 1f6ae5e40d
commit 64d0b4cb70
1 changed files with 4 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "termkey.h" #include "termkey.h"
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -370,7 +371,9 @@ void termkey_advisereadable(termkey_t *tk)
unsigned char buffer[64]; // Smaller than the default size unsigned char buffer[64]; // Smaller than the default size
size_t len = read(tk->fd, buffer, sizeof buffer); size_t len = read(tk->fd, buffer, sizeof buffer);
if(len == -1) if(len == -1 && errno == EAGAIN)
return;
else if(len < 1)
tk->is_closed = 1; tk->is_closed = 1;
else else
termkey_pushinput(tk, buffer, len); termkey_pushinput(tk, buffer, len);