-u triggers setvbuf with _IONBF
This commit is contained in:
parent
57d260971d
commit
0fa85040b3
1 changed files with 7 additions and 12 deletions
19
cat.c
19
cat.c
|
@ -18,15 +18,15 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
if(using_unbuffered_output) {
|
||||
setvbuf(stdin, NULL, _IONBF, 15);
|
||||
setvbuf(stdout, NULL, _IONBF, 15);
|
||||
}
|
||||
|
||||
if(argc == 1 || optind == argc) {
|
||||
cur_in_file = stdin;
|
||||
for(c = fgetc(cur_in_file); c != EOF; c = fgetc(cur_in_file)) {
|
||||
if(using_unbuffered_output) {
|
||||
write(1, &c, 1);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "%c", c);
|
||||
}
|
||||
fprintf(stdout, "%c", c);
|
||||
}
|
||||
fclose(cur_in_file);
|
||||
}
|
||||
|
@ -43,12 +43,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
for(c = fgetc(cur_in_file); c != EOF; c = fgetc(cur_in_file)) {
|
||||
if(using_unbuffered_output) {
|
||||
write(1, &c, 1);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "%c", c);
|
||||
}
|
||||
fprintf(stdout, "%c", c);
|
||||
}
|
||||
fclose(cur_in_file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue