-u triggers setvbuf with _IONBF

This commit is contained in:
Kat R. 2022-02-27 21:38:10 -06:00
parent 57d260971d
commit 0fa85040b3

19
cat.c
View file

@ -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);
}