mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
Merge pull request #2518 from jfinkels/tac-no-line-separators-in-file
tac: handle no line separators in file
This commit is contained in:
commit
00f6fce89d
2 changed files with 13 additions and 1 deletions
|
@ -139,9 +139,16 @@ fn tac(filenames: Vec<String>, before: bool, _: bool, separator: &str) -> i32 {
|
|||
i += 1;
|
||||
}
|
||||
}
|
||||
// If the file contains no line separators, then simply write
|
||||
// the contents of the file directly to stdout.
|
||||
if offsets.is_empty() {
|
||||
out.write_all(&data)
|
||||
.unwrap_or_else(|e| crash!(1, "failed to write to stdout: {}", e));
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
// if there isn't a separator at the end of the file, fake it
|
||||
if offsets.is_empty() || *offsets.last().unwrap() < data.len() - slen {
|
||||
if *offsets.last().unwrap() < data.len() - slen {
|
||||
offsets.push(data.len());
|
||||
}
|
||||
|
||||
|
|
|
@ -68,3 +68,8 @@ fn test_invalid_input() {
|
|||
.fails()
|
||||
.stderr_contains("dir: read error: Invalid argument");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_line_separators() {
|
||||
new_ucmd!().pipe_in("a").succeeds().stdout_is("a");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue