aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c23
1 files changed, 23 insertions, 0 deletions
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)