Merge recent updates from ch7.

This commit is contained in:
Yifan Wu 2022-01-18 04:40:07 -08:00
parent b535f5ba98
commit f6ebd1ac68
4 changed files with 5 additions and 69 deletions

View file

@ -11,7 +11,6 @@ use user_lib::{
close,
read,
};
use alloc::string::String;
#[no_mangle]
pub fn main(argc: usize, argv: &[&str]) -> i32 {
@ -22,13 +21,11 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 {
}
let fd = fd as usize;
let mut buf = [0u8; 16];
let mut s = String::new();
loop {
let size = read(fd, &mut buf) as usize;
if size == 0 { break; }
s.push_str(core::str::from_utf8(&buf[..size]).unwrap());
println!("{}", core::str::from_utf8(&buf[..size]).unwrap());
}
println!("{}", s);
close(fd);
0
}
}

View file

@ -18,7 +18,7 @@ pub fn main() -> i32 {
for i in 0..buffer.len() {
buffer[i] = i as u8;
}
let f = open("testf", OpenFlags::CREATE | OpenFlags::WRONLY);
let f = open("testf\0", OpenFlags::CREATE | OpenFlags::WRONLY);
if f < 0 {
panic!("Open test file failed!");
}
@ -33,4 +33,4 @@ pub fn main() -> i32 {
let speed_kbs = size_mb * 1000000 / time_ms;
println!("{}MiB written, time cost = {}ms, write speed = {}KiB/s", size_mb, time_ms, speed_kbs);
0
}
}

View file

@ -29,6 +29,7 @@ unsafe fn f(count:usize) -> ! {
#[no_mangle]
pub fn main(argc: usize, argv: &[&str]) -> i32 {
let mut count = 0;
if argc == 1 {
count = THREAD_COUNT;
} else if argc == 2 {