Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions rules/cstdlib/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ fn f6(a0: Ptr<u8>) -> Ptr<u8> {
}
}

fn f10(a0: Ptr<u8>, a1: Ptr<u8>) -> Ptr<u8> {
let __resolved = a1.clone();
match ::std::fs::canonicalize(a0.to_rust_string()) {
Ok(__p) => {
let mut __bytes = __p.into_os_string().into_encoded_bytes();
__bytes.push(0);
if __resolved.is_null() {
Ptr::alloc_array(__bytes.into_boxed_slice())
} else {
__resolved.with_slice_mut(__bytes.len(), |__s| __s.copy_from_slice(&__bytes));
__resolved
}
}
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e.raw_os_error().unwrap_or(::libc::EIO));
Ptr::null()
}
}
}

fn f8(a0: AnyPtr, a1: AnyPtr, a2: usize, a3: usize, a4: fn(AnyPtr, AnyPtr) -> i32) -> AnyPtr {
let __base = a1.reinterpret_cast::<u8>();
let mut __lo: isize = 0;
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/out/unsafe/stdlib_h.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,49 @@ pub unsafe fn test_setenv_getenv_0() {
((((libc::strcmp(v, (c"replaced".as_ptr().cast_mut()).cast_const())) == (0)) as i32) != 0)
);
}
pub unsafe fn test_realpath_1() {
let mut buf: [libc::c_char; 4096] = [(0 as libc::c_char); 4096];
assert!(
(((!((libc::realpath((c"/".as_ptr().cast_mut()).cast_const(), buf.as_mut_ptr())).is_null()))
as i32)
!= 0)
);
assert!(
((((libc::strcmp(
(buf.as_mut_ptr()).cast_const(),
(c"/".as_ptr().cast_mut()).cast_const()
)) == (0)) as i32)
!= 0)
);
let mut p: *mut libc::c_char = libc::realpath(
(c"/".as_ptr().cast_mut()).cast_const(),
std::ptr::null_mut(),
);
assert!((((!((p).is_null())) as i32) != 0));
assert!(
((((libc::strcmp((p).cast_const(), (c"/".as_ptr().cast_mut()).cast_const())) == (0))
as i32)
!= 0)
);
libcc2rs::free_unsafe((p as *mut libc::c_char as *mut ::libc::c_void));
(*libcc2rs::cpp2rust_errno_unsafe()) = 0;
assert!(
((((libc::realpath(
(c"/cpp2rust_definitely_missing".as_ptr().cast_mut()).cast_const(),
buf.as_mut_ptr()
))
.is_null()) as i32)
!= 0)
);
assert!(((((*libcc2rs::cpp2rust_errno_unsafe()) == (2)) as i32) != 0));
}
pub fn main() {
unsafe {
std::process::exit(main_0() as i32);
}
}
unsafe fn main_0() -> i32 {
(unsafe { test_setenv_getenv_0() });
(unsafe { test_realpath_1() });
return 0;
}
15 changes: 15 additions & 0 deletions tests/unit/stdlib_h.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// no-compile: refcount
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

Expand All @@ -14,7 +15,21 @@ static void test_setenv_getenv(void) {
assert(strcmp(v, "replaced") == 0);
}

static void test_realpath(void) {
char buf[4096];
assert(realpath("/", buf) != NULL);
assert(strcmp(buf, "/") == 0);
char *p = realpath("/", NULL);
assert(p != NULL);
assert(strcmp(p, "/") == 0);
free(p);
errno = 0;
assert(realpath("/cpp2rust_definitely_missing", buf) == NULL);
assert(errno == ENOENT);
}

int main(void) {
test_setenv_getenv();
test_realpath();
return 0;
}
Loading