mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
tail: Count lines correctly when file ends with two or more newlines
Previously, an extra line would be displayed when a file ended in more than one newline.
This commit is contained in:
parent
daa9812cea
commit
7ad212ff63
1 changed files with 1 additions and 1 deletions
|
@ -33,7 +33,7 @@ static ErrorOr<off_t> find_seek_pos(Core::File& file, int wanted_lines)
|
||||||
TRY(file.seek(pos - 1, SeekMode::SetPosition));
|
TRY(file.seek(pos - 1, SeekMode::SetPosition));
|
||||||
|
|
||||||
auto ch = TRY(file.read_value<u8>());
|
auto ch = TRY(file.read_value<u8>());
|
||||||
if (ch == '\n' && (end - pos) > 1) {
|
if (ch == '\n' && (end - pos) > 0) {
|
||||||
lines++;
|
lines++;
|
||||||
if (lines == wanted_lines)
|
if (lines == wanted_lines)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue