diff options
author | Aki <please@ignore.pl> | 2021-08-21 22:52:11 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-08-21 22:52:11 +0200 |
commit | 6990cca3da5c26148d79b41e4d086183592b0aea (patch) | |
tree | 7ebbbeaab3241e63ef25eefcbcf1dea5dbfe6d82 | |
parent | 38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6 (diff) | |
download | plop-6990cca3da5c26148d79b41e4d086183592b0aea.zip plop-6990cca3da5c26148d79b41e4d086183592b0aea.tar.gz plop-6990cca3da5c26148d79b41e4d086183592b0aea.tar.bz2 |
Merged buffer read_more and prepare
-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); |