cat(1): -u works, kinda, but requires 3 ctrl+D presses
This commit is contained in:
		
							parent
							
								
									cc64ab08da
								
							
						
					
					
						commit
						20e9c19ccd
					
				
							
								
								
									
										32
									
								
								src/cat.rs
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/cat.rs
									
									
									
									
									
								
							@ -18,10 +18,9 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
use std::env;
 | 
			
		||||
use std::fs::{File, read, read_to_string};
 | 
			
		||||
use std::fs::{File, read_to_string};
 | 
			
		||||
use std::io;
 | 
			
		||||
use std::io::{ Read, Write };
 | 
			
		||||
use std::os::unix::io::FromRawFd;
 | 
			
		||||
use std::io::{ BufRead, Read };
 | 
			
		||||
use std::str;
 | 
			
		||||
 | 
			
		||||
use arg::Args;
 | 
			
		||||
@ -50,6 +49,33 @@ fn main() -> ExitCode {
 | 
			
		||||
 | 
			
		||||
  if args.paths.is_empty() { args.paths.push("-".to_string()); }
 | 
			
		||||
 | 
			
		||||
  while args.u {
 | 
			
		||||
    for path in &args.paths {
 | 
			
		||||
      if path == "-" {
 | 
			
		||||
        loop {
 | 
			
		||||
          let mut buf = String::new();
 | 
			
		||||
          match io::stdin().lock().read_line(&mut buf) {
 | 
			
		||||
            Ok(bytes) => {
 | 
			
		||||
              if bytes == 0 { break };
 | 
			
		||||
              print!("{}", buf);
 | 
			
		||||
            },
 | 
			
		||||
            Err(err) => println!("{}", err),
 | 
			
		||||
          };
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        let mut input = String::new();
 | 
			
		||||
        match File::open(path) {
 | 
			
		||||
          Ok(input) => {},
 | 
			
		||||
          Err(_) => {
 | 
			
		||||
            println!("{}: {}: No such file or directory.", &argv0, path);
 | 
			
		||||
            return ExitCode::NoInput;
 | 
			
		||||
          },
 | 
			
		||||
        };
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return ExitCode::Ok;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for path in args.paths {
 | 
			
		||||
    if path == "-" {
 | 
			
		||||
      let mut bytes: Vec<u8> = Vec::new();
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user