release
[hcoop/zz_old/debian/djbdns.git] / readclose.c
1 #include <unistd.h>
2 #include "error.h"
3 #include "readclose.h"
4
5 int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
6 {
7 int r;
8 for (;;) {
9 if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
10 r = read(fd,sa->s + sa->len,bufsize);
11 if (r == -1) if (errno == error_intr) continue;
12 if (r <= 0) { close(fd); return r; }
13 sa->len += r;
14 }
15 }
16
17 int readclose(int fd,stralloc *sa,unsigned int bufsize)
18 {
19 if (!stralloc_copys(sa,"")) { close(fd); return -1; }
20 return readclose_append(fd,sa,bufsize);
21 }