Skip to content

Commit abd2008

Browse files
committed
Add rules for open/read/write/close
1 parent 3ed63ff commit abd2008

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎rules/fcntl/tgt_refcount.rs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ fn f1(a0: i32, a1: i32, va: &[VaArg]) -> i32 {
1313
}
1414

1515
fn f2(a0: Ptr<u8>, a1: i32, va: &[VaArg]) -> i32 {
16-
panic!(
17-
"open is not supported in the refcount model (path={:?}, flags={}, varargs={})",
18-
a0.to_rust_string(),
19-
a1,
20-
va.len()
21-
)
16+
let __mode = match va.first() {
17+
Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t),
18+
None => nix::sys::stat::Mode::empty(),
19+
};
20+
match nix::fcntl::open(
21+
a0.to_rust_string().as_str(),
22+
nix::fcntl::OFlag::from_bits_retain(a1),
23+
__mode,
24+
) {
25+
Ok(__ofd) => FdRegistry::register(__ofd),
26+
Err(__e) => {
27+
libcc2rs::cpp2rust_errno().write(__e as i32);
28+
-1
29+
}
30+
}
2231
}

‎rules/unistd/tgt_refcount.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33

44
use libcc2rs::*;
55

6+
fn f1(a0: i32) -> i32 {
7+
FdRegistry::close(a0)
8+
}
9+
10+
fn f3(a0: i32, a1: AnyPtr, a2: usize) -> isize {
11+
match FdRegistry::with_fd(a0, |__fd| {
12+
a1.reinterpret_cast::<u8>()
13+
.with_slice_mut(a2, |__buf| nix::unistd::read(__fd, __buf))
14+
}) {
15+
Ok(__n) => __n as isize,
16+
Err(__e) => {
17+
libcc2rs::cpp2rust_errno().write(__e as i32);
18+
-1
19+
}
20+
}
21+
}
22+
623
fn f4(a0: Ptr<u8>) -> i32 {
724
match nix::unistd::unlink(a0.to_rust_string().as_str()) {
825
Ok(()) => 0,
@@ -37,6 +54,19 @@ fn f9(a0: Ptr<u8>, a1: usize) -> i32 {
3754
}
3855
}
3956

57+
fn f10(a0: i32, a1: AnyPtr, a2: usize) -> isize {
58+
match FdRegistry::with_fd(a0, |__fd| {
59+
a1.reinterpret_cast::<u8>()
60+
.with_slice(a2, |__buf| nix::unistd::write(__fd, __buf))
61+
}) {
62+
Ok(__n) => __n as isize,
63+
Err(__e) => {
64+
libcc2rs::cpp2rust_errno().write(__e as i32);
65+
-1
66+
}
67+
}
68+
}
69+
4070
fn f11(a0: Ptr<u8>) -> i32 {
4171
match ::std::fs::remove_dir(a0.to_rust_string()) {
4272
Ok(()) => 0,

0 commit comments

Comments
 (0)