cat/cat-mmap: print newline if file doesn't end in one

This commit is contained in:
2024-01-02 23:27:13 +02:00
parent 9fa13079f2
commit 1bd33e76e5
2 changed files with 8 additions and 0 deletions

View File

@@ -23,6 +23,10 @@ bool cat_file(int fd)
if (nwrite == -1)
perror("write");
if (static_cast<uint8_t*>(addr)[st.st_size - 1] != '\n')
if (write(STDOUT_FILENO, "\n", 1) == -1)
perror("write");
if (munmap(addr, st.st_size) == -1)
{
perror("munmap");