parent
0853f60391
commit
ae2ac05ced
|
@ -120,7 +120,30 @@ int main(int argc, char *argv[]) {
|
|||
close(sd);
|
||||
HANDLE_ERROR("read() failed");
|
||||
} else if (i > 0) {
|
||||
(void) write(STDOUT_FILENO, buf, (size_t) i);
|
||||
ptrdiff_t written = 0;
|
||||
const char *bufp = &(buf[0]);
|
||||
while (written < i) {
|
||||
written = write(STDOUT_FILENO, buf, (size_t) i);
|
||||
if (written >= 0) {
|
||||
bufp += written;
|
||||
i -= written;
|
||||
written = 0;
|
||||
} else {
|
||||
errno = 0;
|
||||
switch (errno) {
|
||||
case EAGAIN:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EWOULDBLOCK:
|
||||
#endif
|
||||
case EINTR:
|
||||
break;
|
||||
default:
|
||||
(void) printf("Error while writing output: %s", strerror(errno));
|
||||
close(sd);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue