X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/394938c479925750ffe56c28d281945ba4003a14..635bd88df1273656324ee0c47dba6275259674b4:/charfuncs.c?ds=sidebyside 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; }