Read/Write byte by byte using using fread/fwrite.
Do not read 1024 arbitrary bytes. Slow down output to character atomicity.
This commit is contained in:
parent
14997c2c98
commit
08b9a63710
1 changed files with 5 additions and 5 deletions
10
slow.c
10
slow.c
|
|
@ -4,17 +4,17 @@
|
|||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char line[1024];
|
||||
int linesize = sizeof(line);
|
||||
int useconds = 1000000;
|
||||
char buffer;
|
||||
size_t nread;
|
||||
useconds_t useconds = 1000000; // default 1 second
|
||||
|
||||
if (argc == 2) {
|
||||
useconds = atoi(argv[1]);
|
||||
}
|
||||
|
||||
while(fgets(line, linesize, stdin)) {
|
||||
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
||||
usleep(useconds);
|
||||
fputs(line, stdout);
|
||||
fwrite(&buffer, 1, nread, stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue