Handle read/write errors.

This commit is contained in:
Simon Lieb 2013-08-08 21:03:48 +02:00
parent 7ae9bb1196
commit 841545aa4d
2 changed files with 9 additions and 2 deletions

9
slow.c
View file

@ -31,11 +31,18 @@ int main(int argc, char *argv[]) {
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
usleep(useconds);
fwrite(&buffer, 1, nread, stdout);
if(fwrite(&buffer, 1, nread, stdout) != nread) {
fprintf(stderr, "stdout: write error");
exit(EXIT_FAILURE);
}
if(flush) {
fflush(stdout);
}
}
if(ferror(stdin)) {
fprintf(stderr, "stdin: read error");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}