X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/394938c479925750ffe56c28d281945ba4003a14..584b44f3613a29ce27fc8b87cdd8654d3357ed4f:/charfuncs.c?ds=inline diff --git a/charfuncs.c b/charfuncs.c index c8a140f..778df1c 100644 --- a/charfuncs.c +++ b/charfuncs.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -22,12 +23,11 @@ int buffer_fetchchar(void *ctx, size_t count, unsigned char *c) { struct buffer_ctx *buf = NULL; - size_t i; buf = (struct buffer_ctx *) ctx; - for (i = 0; i < count; i++) { - c[i] = buf->buffer[buf->offset++]; - } + + memcpy(c, &buf->buffer[buf->offset], count); + buf->offset += count; return (((buf->offset) == (buf->size)) ? 1 : 0); } @@ -46,7 +46,6 @@ int buffer_putchar(void *ctx, size_t count, unsigned char *c) { struct buffer_ctx *buf = NULL; size_t newsize = 0; - size_t i; buf = (struct buffer_ctx *) ctx; @@ -57,11 +56,10 @@ int buffer_putchar(void *ctx, size_t count, unsigned char *c) buf->buffer = realloc(buf->buffer, newsize); buf->size = newsize; } - - for (i = 0; i < count; i++) { - buf->buffer[buf->offset++] = c[i]; - } + memcpy(&buf->buffer[buf->offset], c, count); + buf->offset += count; + return 1; }