Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/uu/tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ fn forwards_thru_file(
/// `num_delimiters` instance of `delimiter`. The `file` is left seek'd to the
/// position just after that delimiter.
fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) {
if num_delimiters == 0 {
file.seek(SeekFrom::End(0)).unwrap();
return;
}
// This variable counts the number of delimiters found in the file
// so far (reading from the end of the file toward the beginning).
let mut counter = 0;
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,16 @@ fn test_obsolete_syntax_small_file() {
.stdout_is("a\nb\nc\nd\ne\n");
}

/// Test for obsolete syntax `tail -0 FILE`: print nothing and exit cleanly.
#[test]
fn test_obsolete_syntax_zero_lines_file() {
new_ucmd!()
.args(&["-0", "foobar.txt"])
.succeeds()
.no_stderr()
.no_stdout();
}

/// Test for reading all lines, specified by `tail -n +0`.
#[test]
fn test_positive_zero_lines() {
Expand Down
Loading