Handle read/write errors.
This commit is contained in:
parent
7ae9bb1196
commit
841545aa4d
2 changed files with 9 additions and 2 deletions
9
slow.c
9
slow.c
|
|
@ -31,11 +31,18 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
||||||
usleep(useconds);
|
usleep(useconds);
|
||||||
fwrite(&buffer, 1, nread, stdout);
|
if(fwrite(&buffer, 1, nread, stdout) != nread) {
|
||||||
|
fprintf(stderr, "stdout: write error");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
if(flush) {
|
if(flush) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(ferror(stdin)) {
|
||||||
|
fprintf(stderr, "stdin: read error");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -1,4 +1,4 @@
|
||||||
- [x] Add forced flush option. -f ? -F ?
|
- [x] Add forced flush option. -f ? -F ?
|
||||||
- [ ] Write man page
|
- [ ] Write man page
|
||||||
- [ ] Send errors to sderr
|
- [x] Send errors to sderr
|
||||||
- [ ] Release v1
|
- [ ] Release v1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue