Skip to content

Commit 5989eff

Browse files
committed
Add unlink TODO
1 parent c2760c5 commit 5989eff

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

tests/unit/out/unsafe/stdio.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub unsafe fn test_fileno_3() {
130130
}) == (2)) as i32)
131131
!= 0)
132132
);
133+
let mut file: *const u8 = (b"/tmp/cpp2rust_fileno_test.tmp\0".as_ptr().cast_mut()).cast_const();
133134
let mut fp: *mut ::std::fs::File =
134135
match std::ffi::CStr::from_ptr((b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8)
135136
.to_str()
@@ -138,12 +139,9 @@ pub unsafe fn test_fileno_3() {
138139
v if v == "rb" => std::fs::OpenOptions::new()
139140
.read(true)
140141
.open(
141-
std::ffi::CStr::from_ptr(
142-
(b"/tmp/cpp2rust_fileno_test.tmp\0".as_ptr().cast_mut()).cast_const()
143-
as *const i8,
144-
)
145-
.to_str()
146-
.expect("invalid c-string"),
142+
std::ffi::CStr::from_ptr(file as *const i8)
143+
.to_str()
144+
.expect("invalid c-string"),
147145
)
148146
.ok()
149147
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),
@@ -152,12 +150,9 @@ pub unsafe fn test_fileno_3() {
152150
.create(true)
153151
.truncate(true)
154152
.open(
155-
std::ffi::CStr::from_ptr(
156-
(b"/tmp/cpp2rust_fileno_test.tmp\0".as_ptr().cast_mut()).cast_const()
157-
as *const i8,
158-
)
159-
.to_str()
160-
.expect("invalid c-string"),
153+
std::ffi::CStr::from_ptr(file as *const i8)
154+
.to_str()
155+
.expect("invalid c-string"),
161156
)
162157
.ok()
163158
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),

tests/unit/stdio.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ static void test_fileno(void) {
2929
assert(fileno(stdin) == 0);
3030
assert(fileno(stdout) == 1);
3131
assert(fileno(stderr) == 2);
32-
FILE *fp = fopen("/tmp/cpp2rust_fileno_test.tmp", "wb");
32+
const char* file = "/tmp/cpp2rust_fileno_test.tmp";
33+
FILE *fp = fopen(file, "wb");
3334
assert(fp != NULL);
3435
assert(fileno(fp) > 2);
3536
fclose(fp);
37+
// TODO: uncomment when unlink is available
38+
// assert(unlink(file) == 0);
3639
}
3740

3841
int main(void) {

0 commit comments

Comments
 (0)