Skip to content

Change the file example to work in DOSBox or real hardware #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/dos_tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ entry!(main);
fn main() {
allocator_test();
file_read_test();

println!("Hello, World!");
}