MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / main

Function main

user/src/bin/cat.rs:11–32  ·  view source on GitHub ↗
(argc: usize, argv: &[&str])

Source from the content-addressed store, hash-verified

9
10#[no_mangle]
11pub fn main(argc: usize, argv: &[&str]) -> i32 {
12 println!("argc = {}", argc);
13 for (i, arg) in argv.iter().enumerate() {
14 println!("argv[{}] = {}", i, arg);
15 }
16 assert!(argc == 2);
17 let fd = open(argv[1], OpenFlags::RDONLY);
18 if fd == -1 {
19 panic!("Error occurred when opening file");
20 }
21 let fd = fd as usize;
22 let mut buf = [0u8; 256];
23 loop {
24 let size = read(fd, &mut buf) as usize;
25 if size == 0 {
26 break;
27 }
28 print!("{}", core::str::from_utf8(&buf[..size]).unwrap());
29 }
30 close(fd);
31 0
32}

Callers

nothing calls this directly

Calls 3

openFunction · 0.85
readFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected