os/syscall/fs.rs
1//! File and filesystem-related syscalls
2
3const FD_STDOUT: usize = 1;
4
5/// write buf of length `len` to a file with `fd`
6pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
7 match fd {
8 FD_STDOUT => {
9 let slice = unsafe { core::slice::from_raw_parts(buf, len) };
10 let str = core::str::from_utf8(slice).unwrap();
11 print!("{}", str);
12 len as isize
13 }
14 _ => {
15 panic!("Unsupported fd in sys_write!");
16 }
17 }
18}