From d7c623b8c762b4b750ed62464d34cb241c25e7d4 Mon Sep 17 00:00:00 2001 From: thorkill Date: Tue, 30 Jun 2015 18:10:00 +0200 Subject: [PATCH] Revert "Changed int size into size_t" This reverts commit f755d57f4ebb094965d19de63aad672ad238b2ec. --- src/buffer.c | 16 ++++++++-------- src/buffer.h | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index bd29e49a..ac57d1c4 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -22,9 +22,9 @@ #include "buffer.h" #include "xalloc.h" -void buffer_compact(buffer_t *buffer, size_t maxsize) { +void buffer_compact(buffer_t *buffer, int maxsize) { if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) { - memmove(buffer->data, buffer->data + buffer->offset, (size_t)(buffer->len - buffer->offset)); + memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset); buffer->len -= buffer->offset; buffer->offset = 0; } @@ -32,7 +32,7 @@ void buffer_compact(buffer_t *buffer, size_t maxsize) { // Make sure we can add size bytes to the buffer, and return a pointer to the start of those bytes. -char *buffer_prepare(buffer_t *buffer, size_t size) { +char *buffer_prepare(buffer_t *buffer, int size) { if(!buffer->data) { buffer->maxlen = size; buffer->data = xmalloc(size); @@ -58,7 +58,7 @@ char *buffer_prepare(buffer_t *buffer, size_t size) { // Copy data into the buffer. -void buffer_add(buffer_t *buffer, const char *data, size_t size) { +void buffer_add(buffer_t *buffer, const char *data, int size) { memcpy(buffer_prepare(buffer, size), data, size); } @@ -67,7 +67,7 @@ void buffer_add(buffer_t *buffer, const char *data, size_t size) { static char *buffer_consume(buffer_t *buffer, int size) { char *start = buffer->data + buffer->offset; - buffer->offset += (size_t)size; + buffer->offset += size; if(buffer->offset >= buffer->len) { buffer->offset = 0; @@ -85,18 +85,18 @@ char *buffer_readline(buffer_t *buffer) { if(!newline) return NULL; - int len = (int)(newline + 1 - (buffer->data + buffer->offset)); + int len = newline + 1 - (buffer->data + buffer->offset); *newline = 0; return buffer_consume(buffer, len); } // Check if we have enough bytes in the buffer, and if so, return a pointer to the start of them. -char *buffer_read(buffer_t *buffer, size_t size) { +char *buffer_read(buffer_t *buffer, int size) { if(buffer->len - buffer->offset < size) return NULL; - return buffer_consume(buffer, (int)size); + return buffer_consume(buffer, size); } void buffer_clear(buffer_t *buffer) { diff --git a/src/buffer.h b/src/buffer.h index 39d3b538..a96c15aa 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -3,16 +3,16 @@ typedef struct buffer_t { char *data; - size_t maxlen; - size_t len; - unsigned int offset; + int maxlen; + int len; + int offset; } buffer_t; -extern void buffer_compact(buffer_t *buffer, size_t maxsize); -extern char *buffer_prepare(buffer_t *buffer, size_t size); -extern void buffer_add(buffer_t *buffer, const char *data, size_t size); +extern void buffer_compact(buffer_t *buffer, int maxsize); +extern char *buffer_prepare(buffer_t *buffer, int size); +extern void buffer_add(buffer_t *buffer, const char *data, int size); extern char *buffer_readline(buffer_t *buffer); -extern char *buffer_read(buffer_t *buffer, size_t size); +extern char *buffer_read(buffer_t *buffer, int size); extern void buffer_clear(buffer_t *buffer); #endif