summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-08-21 22:52:11 +0200
committerAki <please@ignore.pl>2021-08-21 22:52:11 +0200
commit6990cca3da5c26148d79b41e4d086183592b0aea (patch)
tree7ebbbeaab3241e63ef25eefcbcf1dea5dbfe6d82
parent38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6 (diff)
downloadplop-6990cca3da5c26148d79b41e4d086183592b0aea.zip
plop-6990cca3da5c26148d79b41e4d086183592b0aea.tar.gz
plop-6990cca3da5c26148d79b41e4d086183592b0aea.tar.bz2
Merged buffer read_more and prepare
-rw-r--r--buffer.c25
-rw-r--r--buffer.h1
2 files changed, 7 insertions, 19 deletions
diff --git a/buffer.c b/buffer.c
index ab39cb7..0261522 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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)
diff --git a/buffer.h b/buffer.h
index 1a614ec..d82ee0b 100644
--- a/buffer.h
+++ b/buffer.h
@@ -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);