/****************************************************************************** * This program reads bytes from a binary file and copies them to another file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn copyBinaryFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc> { binmode(ifh); binmode(ofh); let mut c:u8 = 0; while getbyte(c,ifh) { putbyte(c,ofh); } close(ifh)?; close(ofh)?; } fn main() { let args: Vec = env::args().collect(); if args.len() != 3 { println!("Syntax: {} {{fromFilespec}} {{toFilespec}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut fromFilespec:String = args[1]; let mut toFilespec:String = args[2]; match (|| -> Result<(), Arc>{ copyBinaryFile(&fromFilespec, &toFilespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }