From a4081fd605526e053e4a3f31a8b147458d2878fa Mon Sep 17 00:00:00 2001 From: Edwin Amsler Date: Mon, 16 Jan 2023 22:15:14 -0600 Subject: [PATCH] Change the file example to work in DOSBox or real hardware --- src/dos_tests/file.rs | 16 ++-------------- src/main.rs | 2 ++ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/dos_tests/file.rs b/src/dos_tests/file.rs index f4be2e5..b2098d5 100644 --- a/src/dos_tests/file.rs +++ b/src/dos_tests/file.rs @@ -2,26 +2,14 @@ use rust_dos::*; #[allow(dead_code)] pub(crate) fn file_read_test() { - let test_file = dos::file::File::open("test.txt").unwrap(); - let mut buffer = [0; 20]; - let bytes_read = test_file.read(&mut buffer).unwrap(); - println!("{} bytes read", bytes_read); - println!("{}", core::str::from_utf8(&buffer).unwrap()); - match test_file.close() { - Ok(_) => println!("File closed"), - Err(_) => println!("Error closing file") - } - - let test_file = dos::file::File::open("C:\\AUTOEXEC.BAT").unwrap(); + let test_file = dos::file::File::open("C:\\AUTOEXEC.BAT"); + let test_file = test_file.unwrap_or(dos::file::File::open("README.md").unwrap()); let mut buffer = [0; 100]; let bytes_read = test_file.read(&mut buffer).unwrap(); println!("{} bytes read", bytes_read); println!("{}", core::str::from_utf8(&buffer).unwrap()); - match test_file.close() { Ok(_) => println!("File closed"), Err(_) => println!("Error closing file") } - - println!("Hello, World!"); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3b2da1f..6a79156 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,4 +15,6 @@ entry!(main); fn main() { allocator_test(); file_read_test(); + + println!("Hello, World!"); }