cat: print newline after file contents
This commit is contained in:
parent
23192e4cab
commit
d5ffbda67d
1 changed files with 5 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ int kcmd_cat(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
char lastchar = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int n = read(fd, buf, sizeof(buf));
|
int n = read(fd, buf, sizeof(buf));
|
||||||
|
|
@ -47,12 +48,16 @@ int kcmd_cat(int argc, char **argv)
|
||||||
kprintf("Failed to read %s: %s\n", argv[1], strerror(-n));
|
kprintf("Failed to read %s: %s\n", argv[1], strerror(-n));
|
||||||
return 1;
|
return 1;
|
||||||
} else if (n == 0) {
|
} else if (n == 0) {
|
||||||
|
if(lastchar != '\n')
|
||||||
|
kprintf("\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
console_write(buf[i]);
|
console_write(buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastchar = buf[n - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue