Implement growing the buffer after input

This commit is contained in:
Paul LeoNerd Evans 2008-02-10 20:29:59 +00:00
parent 53b0d0aca9
commit c36c12b53a
1 changed files with 5 additions and 2 deletions

View File

@ -640,8 +640,11 @@ termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key)
void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen)
{
if(tk->buffstart + tk->buffcount + inputlen > tk->buffsize) {
fprintf(stderr, "TODO! Extend input buffer!\n");
exit(0);
while(tk->buffstart + tk->buffcount + inputlen > tk->buffsize)
tk->buffsize *= 2;
unsigned char *newbuffer = realloc(tk->buffer, tk->buffsize);
tk->buffer = newbuffer;
}
// Not strcpy just in case of NUL bytes