From 82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Wed, 18 Jan 2012 13:39:50 +0000 Subject: Added termkey_push_bytes(), a new API for providing input bytes --- termkey.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'termkey.c') diff --git a/termkey.c b/termkey.c index a55b106..249fc22 100644 --- a/termkey.c +++ b/termkey.c @@ -976,6 +976,29 @@ retry: } } +size_t termkey_push_bytes(TermKey *tk, const char *bytes, size_t len) +{ + if(tk->buffstart) { + memmove(tk->buffer, tk->buffer + tk->buffstart, tk->buffcount); + tk->buffstart = 0; + } + + /* Not expecting it ever to be greater but doesn't hurt to handle that */ + if(tk->buffcount >= tk->buffsize) { + errno = ENOMEM; + return (size_t)-1; + } + + if(len > tk->buffsize - tk->buffcount) + len = tk->buffsize - tk->buffcount; + + // memcpy(), not strncpy() in case of null bytes in input + memcpy(tk->buffer + tk->buffcount, bytes, len); + tk->buffcount += len; + + return len; +} + TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name) { if(!sym) -- cgit v1.2.3-70-g09d2