diff options
-rw-r--r-- | buffer.c | 25 | ||||
-rw-r--r-- | buffer.h | 1 |
2 files changed, 7 insertions, 19 deletions
@@ -26,15 +26,18 @@ int buffer_grow(struct buffer * b) return allocated; } -int buffer_read_more(int fd, struct buffer * in, int minimum_length) +int buffer_prepare_at_least(int fd, struct buffer * in, int minimum_length) { + const int remaining_bytes = in->length - in->next; + + if (remaining_bytes >= minimum_length) + return remaining_bytes; + const int free_space = in->allocated + in->offset - in->length - 1; while (free_space < minimum_length) - { if (-1 == buffer_grow(in)) return -1; - } if (0 < in->offset) { @@ -50,21 +53,7 @@ int buffer_read_more(int fd, struct buffer * in, int minimum_length) in->length += length; - return length; -} - -int buffer_prepare_at_least(int fd, struct buffer * in, int minimum_length) -{ - const int remaining_bytes = in->length - in->next; - - if (remaining_bytes < minimum_length) - { - const int res = buffer_read_more(fd, in, minimum_length); - if (-1 == res) - return res; - } - - return remaining_bytes; + return in->length - in->next; } int buffer_until(struct buffer * b, const char * pattern, int pattern_length) @@ -10,6 +10,5 @@ struct buffer }; int buffer_grow(struct buffer *); -int buffer_read_more(const int, struct buffer *, const int); int buffer_prepare_at_least(const int, struct buffer *, const int); int buffer_until(struct buffer *, const char *, const int); |