1
0
forked from bonsai/harakit

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 */ char buf[4096]; /* buffer for buffered reading */
if (u) { if (u) {
while (byte != EOF) { while ((byte = fgetc(file)) != EOF) { putchar(byte); }
byte = fgetc(file);
putchar(byte);
}
} else { } else {
while (byte != EOF) { while ((byte = fgetc(file)) != EOF) {
byte = fgetc(file); if (p > sizeof(buf) - 1) {
if (p > sizeof(buf)) {
fputs(buf, stdout); fputs(buf, stdout);
p = 0; p = 0;
} else { } else {
buf[p] = byte; buf[p] = byte;
p += 1; p++;
} }
} }