summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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);