forked from bonsai/harakit
cat(1p): fixed storing EOF in buffer
This commit is contained in:
parent
043b20a150
commit
3a410edddc
12
src/cat.c
12
src/cat.c
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user