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 */
|
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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user