Skip to content

Commit 2ec4e25

Browse files
committed
Add rules for open flags
1 parent 46159fd commit 2ec4e25

9 files changed

Lines changed: 98 additions & 9 deletions

File tree

‎rules/fcntl/src.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ template <typename... Args>
1212
int f2(const char *a0, int a1, Args... args) {
1313
return open(a0, a1, args...);
1414
}
15+
16+
int f3(void) { return O_CREAT; }
17+
int f4(void) { return O_TRUNC; }
18+
int f5(void) { return O_APPEND; }
19+
int f6(void) { return O_EXCL; }
20+
int f7(void) { return O_NONBLOCK; }
21+
int f8(void) { return O_CLOEXEC; }
22+
int f9(void) { return O_RDONLY; }
23+
int f10(void) { return O_WRONLY; }
24+
int f11(void) { return O_RDWR; }

‎rules/fcntl/tgt_refcount.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,39 @@ fn f2(a0: Ptr<u8>, a1: i32, va: &[VaArg]) -> i32 {
2929
}
3030
}
3131
}
32+
33+
fn f3() -> i32 {
34+
::libc::O_CREAT
35+
}
36+
37+
fn f4() -> i32 {
38+
::libc::O_TRUNC
39+
}
40+
41+
fn f5() -> i32 {
42+
::libc::O_APPEND
43+
}
44+
45+
fn f6() -> i32 {
46+
::libc::O_EXCL
47+
}
48+
49+
fn f7() -> i32 {
50+
::libc::O_NONBLOCK
51+
}
52+
53+
fn f8() -> i32 {
54+
::libc::O_CLOEXEC
55+
}
56+
57+
fn f9() -> i32 {
58+
::libc::O_RDONLY
59+
}
60+
61+
fn f10() -> i32 {
62+
::libc::O_WRONLY
63+
}
64+
65+
fn f11() -> i32 {
66+
::libc::O_RDWR
67+
}

‎rules/fcntl/tgt_unsafe.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,39 @@ unsafe extern "C" {
55
fn f1(a0: i32, a1: i32, ...) -> i32;
66
fn f2(a0: *const i8, a1: i32, ...) -> i32;
77
}
8+
9+
unsafe fn f3() -> i32 {
10+
::libc::O_CREAT
11+
}
12+
13+
unsafe fn f4() -> i32 {
14+
::libc::O_TRUNC
15+
}
16+
17+
unsafe fn f5() -> i32 {
18+
::libc::O_APPEND
19+
}
20+
21+
unsafe fn f6() -> i32 {
22+
::libc::O_EXCL
23+
}
24+
25+
unsafe fn f7() -> i32 {
26+
::libc::O_NONBLOCK
27+
}
28+
29+
unsafe fn f8() -> i32 {
30+
::libc::O_CLOEXEC
31+
}
32+
33+
unsafe fn f9() -> i32 {
34+
::libc::O_RDONLY
35+
}
36+
37+
unsafe fn f10() -> i32 {
38+
::libc::O_WRONLY
39+
}
40+
41+
unsafe fn f11() -> i32 {
42+
::libc::O_RDWR
43+
}

‎tests/ub/out/refcount/fd_double_close.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main_0() -> i32 {
1919
Ptr::from_string_literal(b"/dev/null")
2020
.to_rust_string()
2121
.as_str(),
22-
nix::fcntl::OFlag::from_bits_retain(0),
22+
nix::fcntl::OFlag::from_bits_retain(::libc::O_RDONLY),
2323
__mode,
2424
) {
2525
Ok(__ofd) => FdRegistry::register(__ofd),

‎tests/ub/out/refcount/fd_use_after_close.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main_0() -> i32 {
1919
Ptr::from_string_literal(b"/dev/null")
2020
.to_rust_string()
2121
.as_str(),
22-
nix::fcntl::OFlag::from_bits_retain(0),
22+
nix::fcntl::OFlag::from_bits_retain(::libc::O_RDONLY),
2323
__mode,
2424
) {
2525
Ok(__ofd) => FdRegistry::register(__ofd),

‎tests/ub/out/unsafe/fd_double_close.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unsafe fn main_0() -> i32 {
1515
let mut fd: i32 = (unsafe {
1616
libc::open(
1717
(c"/dev/null".as_ptr().cast_mut()).cast_const() as *const i8,
18-
0 as i32,
18+
::libc::O_RDONLY as i32,
1919
)
2020
});
2121
libc::close(fd);

‎tests/ub/out/unsafe/fd_use_after_close.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unsafe fn main_0() -> i32 {
1515
let mut fd: i32 = (unsafe {
1616
libc::open(
1717
(c"/dev/null".as_ptr().cast_mut()).cast_const() as *const i8,
18-
0 as i32,
18+
::libc::O_RDONLY as i32,
1919
)
2020
});
2121
libc::close(fd);

‎tests/unit/out/refcount/fd_io.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ fn main_0() -> i32 {
2020
};
2121
match nix::fcntl::open(
2222
(*path.borrow()).to_rust_string().as_str(),
23-
nix::fcntl::OFlag::from_bits_retain(((1 | 64) | 512)),
23+
nix::fcntl::OFlag::from_bits_retain(
24+
((::libc::O_WRONLY | ::libc::O_CREAT) | ::libc::O_TRUNC),
25+
),
2426
__mode,
2527
) {
2628
Ok(__ofd) => FdRegistry::register(__ofd),
@@ -54,7 +56,7 @@ fn main_0() -> i32 {
5456
};
5557
match nix::fcntl::open(
5658
(*path.borrow()).to_rust_string().as_str(),
57-
nix::fcntl::OFlag::from_bits_retain(0),
59+
nix::fcntl::OFlag::from_bits_retain(::libc::O_RDONLY),
5860
__mode,
5961
) {
6062
Ok(__ofd) => FdRegistry::register(__ofd),

‎tests/unit/out/unsafe/fd_io.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ pub fn main() {
1414
unsafe fn main_0() -> i32 {
1515
let mut path: *const libc::c_char =
1616
(c"/tmp/cpp2rust_fd_io_test.tmp".as_ptr().cast_mut()).cast_const();
17-
let mut fd: i32 =
18-
(unsafe { libc::open(path as *const i8, (((1) | (64)) | (512)) as i32, (420)) });
17+
let mut fd: i32 = (unsafe {
18+
libc::open(
19+
path as *const i8,
20+
(((::libc::O_WRONLY) | (::libc::O_CREAT)) | (::libc::O_TRUNC)) as i32,
21+
(420),
22+
)
23+
});
1924
assert!(((((fd) >= (0)) as i32) != 0));
2025
assert!(
2126
((((libc::write(
@@ -26,7 +31,7 @@ unsafe fn main_0() -> i32 {
2631
!= 0)
2732
);
2833
assert!(((((libc::close(fd)) == (0)) as i32) != 0));
29-
fd = (unsafe { libc::open(path as *const i8, 0 as i32) });
34+
fd = (unsafe { libc::open(path as *const i8, ::libc::O_RDONLY as i32) });
3035
assert!(((((fd) >= (0)) as i32) != 0));
3136
let mut buf: [libc::c_char; 16] = [(0 as libc::c_char); 16];
3237
{

0 commit comments

Comments
 (0)