diff options
Diffstat (limited to '')
-rw-r--r-- | feedbuffer.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/feedbuffer.c b/feedbuffer.c new file mode 100644 index 0000000..59ecae0 --- /dev/null +++ b/feedbuffer.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +feedbuffer(int fd, struct buffer *buffer, const char *fname) +{ + ssize_t r; + if (buffer->length == buffer->size) + buffer->buf = erealloc(buffer->buf, buffer->size += 8096); +again: + r = read(fd, &buffer->buf[buffer->length], buffer->size - buffer->length); + if (r <= 0) { + if (!r) + return 1; + if (errno == EINTR) + goto again; + weprintf("%s:", fname); + return -1; + } + buffer->length += (size_t)r; + return 0; +} |