cat(1p): fixed storing EOF in buffer

This commit is contained in:
Emma Tebibyte 2023-08-28 16:03:36 -06:00
parent 043b20a150
commit 3a410edddc
Signed by untrusted user: emma
GPG Key ID: 6D661C738815E7DD

View File

@ -31,19 +31,15 @@ void cat(FILE *file, bool u) {
char buf[4096]; /* buffer for buffered reading */
if (u) {
while (byte != EOF) {
byte = fgetc(file);
putchar(byte);
}
while ((byte = fgetc(file)) != EOF) { putchar(byte); }
} else {
while (byte != EOF) {
byte = fgetc(file);
if (p > sizeof(buf)) {
while ((byte = fgetc(file)) != EOF) {
if (p > sizeof(buf) - 1) {
fputs(buf, stdout);
p = 0;
} else {
buf[p] = byte;
p += 1;
p++;
}
}