Skip to content

Commit 5460045

Browse files
committed
shell/cat: Add trailing LF if whatever we cat doesn't have it
1 parent ce3b6b8 commit 5460045

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lib/fs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ display_file(stream_t *st, const char *path, int hex)
405405
return err;
406406
}
407407
size_t offset = 0;
408+
int need_lf = 0;
408409
while(1) {
409410
ssize_t r = fs_read(fp, buf, sizeof(buf));
410411
if(r < 0) {
@@ -419,9 +420,12 @@ display_file(stream_t *st, const char *path, int hex)
419420
offset += r;
420421
} else {
421422
stream_write(st, buf, r, 0);
423+
need_lf = buf[r - 1] != '\n';
422424
}
423425
}
424426
fs_close(fp);
427+
if(need_lf)
428+
printf("\n");
425429
return err;
426430
}
427431

0 commit comments

Comments
 (0)