diff --git a/wc/wc.rs b/wc/wc.rs index 88fbe53cd..76f21b1a4 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -60,12 +60,10 @@ fn main() { } if (matches.opt_present("version")) { - println("cat 1.0.0"); + println("wc 1.0.0"); return; } - - let mut files = matches.free.clone(); if files.is_empty() { files = ~[~"-"]; @@ -113,7 +111,11 @@ pub fn wc(files: ~[~str], matches: &Matches) { // hence the option wrapped in a result here match result(| | reader.read_until(LF)) { Ok(Some(raw_line)) => { - line_count += 1; + // GNU 'wc' only counts lines that end in LF as lines + if (raw_line.iter().last().unwrap() == &LF) { + line_count += 1; + } + byte_count += raw_line.iter().len(); // try and convert the bytes to UTF-8 first