aboutsummaryrefslogtreecommitdiffstats
path: root/feedbuffer.c
blob: 59ecae0d0d4a02b6a406bdcf0a12b4400da3aeed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}