diff options
| author | Fuwn <[email protected]> | 2022-01-04 15:31:37 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-04 15:31:37 -0800 |
| commit | 651d0f46df0acb38b9d157dad234ae2cada79a90 (patch) | |
| tree | d2079f9f68f7ef89e7498d07eb306f17040422c8 /crates/user/reading_and_writing | |
| parent | chore(crates): migrate to edition 2021 (diff) | |
| download | driver-651d0f46df0acb38b9d157dad234ae2cada79a90.tar.xz driver-651d0f46df0acb38b9d157dad234ae2cada79a90.zip | |
feat(crates): new userspace examples
Thanks, StephanvanSchaik.
Diffstat (limited to 'crates/user/reading_and_writing')
| -rw-r--r-- | crates/user/reading_and_writing/Cargo.toml | 5 | ||||
| -rw-r--r-- | crates/user/reading_and_writing/src/main.rs | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/crates/user/reading_and_writing/Cargo.toml b/crates/user/reading_and_writing/Cargo.toml new file mode 100644 index 0000000..5f2895d --- /dev/null +++ b/crates/user/reading_and_writing/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "reading_and_writing" +version = "0.1.0" +edition = "2021" +license = "MIT" diff --git a/crates/user/reading_and_writing/src/main.rs b/crates/user/reading_and_writing/src/main.rs new file mode 100644 index 0000000..ff6d5d7 --- /dev/null +++ b/crates/user/reading_and_writing/src/main.rs @@ -0,0 +1,21 @@ +use std::io::{Read, Write}; + +fn main() -> Result<(), std::io::Error> { + let mut file = std::fs::OpenOptions::new() + .read(true) + .write(true) + .create(false) + .open("\\??\\Example")?; + + file.write_all("Hello, World!".as_bytes())?; + + let mut data = vec![0u8; 4096]; + let size = file.read(&mut data)?; + + match std::str::from_utf8(&data[..size]) { + Ok(s) => println!("read {} bytes from \"{}\"", size, s), + _ => println!("read {} bytes: {:x?}", size, &data[..size]), + } + + Ok(()) +} |