diff options
author | joe <joe@jerkface.net> | 2015-05-08 23:07:47 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2015-05-08 23:07:47 -0400 |
commit | 220534453eecc2c07ad710d72268aafd20b83138 (patch) | |
tree | 469bd5db135e31b7ea908152aa3389b9b1e06d5b /readclose.c |
initial commit
Diffstat (limited to 'readclose.c')
-rw-r--r-- | readclose.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/readclose.c b/readclose.c new file mode 100644 index 0000000..9d83007 --- /dev/null +++ b/readclose.c | |||
@@ -0,0 +1,23 @@ | |||
1 | /* Public domain. */ | ||
2 | |||
3 | #include <unistd.h> | ||
4 | #include "error.h" | ||
5 | #include "readclose.h" | ||
6 | |||
7 | int readclose_append(int fd,stralloc *sa,unsigned int bufsize) | ||
8 | { | ||
9 | int r; | ||
10 | for (;;) { | ||
11 | if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; } | ||
12 | r = read(fd,sa->s + sa->len,bufsize); | ||
13 | if (r == -1) if (errno == error_intr) continue; | ||
14 | if (r <= 0) { close(fd); return r; } | ||
15 | sa->len += r; | ||
16 | } | ||
17 | } | ||
18 | |||
19 | int readclose(int fd,stralloc *sa,unsigned int bufsize) | ||
20 | { | ||
21 | if (!stralloc_copys(sa,"")) { close(fd); return -1; } | ||
22 | return readclose_append(fd,sa,bufsize); | ||
23 | } | ||