You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
530 B
C
22 lines
530 B
C
22 years ago
|
#include <unistd.h>
|
||
|
#include <errno.h>
|
||
|
#include "readclose.h"
|
||
|
|
||
|
int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
|
||
|
{
|
||
|
int r;
|
||
|
for (;;) {
|
||
|
if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
|
||
|
r = read(fd,sa->s + sa->len,bufsize);
|
||
|
if (r == -1) if (errno == EINTR) continue;
|
||
|
if (r <= 0) { close(fd); return r; }
|
||
|
sa->len += r;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int readclose(int fd,stralloc *sa,unsigned int bufsize)
|
||
|
{
|
||
|
if (!stralloc_copys(sa,"")) { close(fd); return -1; }
|
||
|
return readclose_append(fd,sa,bufsize);
|
||
|
}
|