1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| #![no_std]
#![no_main]
#[macro_use]
#[path = "../../../rbrt/ulib.rs"]
mod ulib;
use ulib::*;
fn copy(fd: i64) -> i64 {
let mut buf = [0u8; 512];
loop {
let n = read(fd, &mut buf);
if n <= 0 {
return n; }
write_all(1, &buf[..n as usize]);
}
}
fn main() -> i64 {
if argc() < 2 {
return if copy(0) < 0 { 1 } else { 0 };
}
let mut status = 0;
for i in 1..argc() {
let name = arg(i).unwrap_or("");
let fd = if name == "-" { 0 } else { open(name, 0) };
let r = if fd < 0 { fd } else { copy(fd) };
if r < 0 {
eprintln!("cat: {}: {}", name, strerror(r));
status = 1;
}
if fd > 0 {
close(fd);
}
}
status
}
|