/****************************************************************************** * This program simply writes the bytes 0 - 256 to a binary file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn writeBinaryFile(filespec:&str) -> Result<(), Arc> { binmode(ofh); { let mut b:isize = 0; while b <= 255 { putbyte(b,ofh); b += 1; } } close(ofh)?; } fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc>{ writeBinaryFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }