Use do_write function in place of self-written replacement

This commit is contained in:
ZyX 2014-08-06 22:32:39 +04:00
parent 0a6bb9ce08
commit 660925f0c2
1 changed files with 1 additions and 24 deletions

View File

@ -123,30 +123,7 @@ int main(int argc, char *argv[]) {
close(sd);
HANDLE_ERROR("read() failed");
} else if (read_size > 0) {
ptrdiff_t written = 0;
const char *bufp = &(buf[0]);
while (written < read_size) {
written = write(STDOUT_FILENO, buf, (size_t) read_size);
if (written >= 0) {
bufp += written;
read_size -= 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;
}
}
}
do_write(STDOUT_FILENO, buf, (size_t) read_size);
}
}