Add parameter forcing flush after each bytes.
This commit is contained in:
parent
10619c50aa
commit
d696b7ba45
2 changed files with 9 additions and 2 deletions
9
slow.c
9
slow.c
|
|
@ -8,7 +8,7 @@
|
|||
char *argv0;
|
||||
|
||||
void usage() {
|
||||
printf("usage: %s [-t usec]\n", argv0);
|
||||
printf("usage: %s [-t usec] [-F]\n", argv0);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -16,11 +16,15 @@ int main(int argc, char *argv[]) {
|
|||
char buffer;
|
||||
size_t nread;
|
||||
useconds_t useconds = 1000000; // default 1 second
|
||||
unsigned int flush = 0;
|
||||
|
||||
ARGBEGIN {
|
||||
case 't':
|
||||
useconds = atoi(EARGF(usage()));
|
||||
break;
|
||||
case 'F':
|
||||
flush = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
|
@ -28,6 +32,9 @@ int main(int argc, char *argv[]) {
|
|||
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
||||
usleep(useconds);
|
||||
fwrite(&buffer, 1, nread, stdout);
|
||||
if(flush) {
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
2
todo.txt
2
todo.txt
|
|
@ -1,4 +1,4 @@
|
|||
- [ ] Add forced flush option. -f ? -F ?
|
||||
- [x] Add forced flush option. -f ? -F ?
|
||||
- [ ] Write man page
|
||||
- [ ] Send errors to sderr
|
||||
- [ ] Release v1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue