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
2 changes: 1 addition & 1 deletion rules/unistd/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn f3(a0: i32, a1: AnyPtr, a2: usize) -> isize {
}

fn f4(a0: Ptr<i8>) -> i32 {
match nix::unistd::unlink(a0.to_rust_string().as_str()) {
match a0.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/fd_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn main_0() -> i32 {
);
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/fstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main_0() -> i32 {
assert!(({ ({ (*st.borrow()).st_size } == (5 as ::libc::off_t)) }));
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/isatty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main_0() -> i32 {
);
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/lseek_ftruncate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn main_0() -> i32 {
);
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/socket_unix_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn main_0() -> i32 {
({ check_name_0(fd, array_field_ptr!(un, sun_path)) });
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(array_field_ptr!(un, sun_path).to_rust_string().as_str()) {
(match array_field_ptr!(un, sun_path).with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/out/refcount/stdcopy_ostream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ fn main_0() -> i32 {
&& (((*buf.borrow())[(15) as usize] as i32) == (('2' as i8) as i32))
})
);
match nix::unistd::unlink(file.decay().to_rust_string().as_str()) {
match file
.decay()
.with_c_bytes(|__path| nix::unistd::unlink(__path))
{
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn test_fileno_3() {
__r
};
assert!(
(match nix::unistd::unlink(file.to_rust_string().as_str()) {
(match file.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/out/refcount/stdio_nofd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn test_fputc_fputs_0() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -327,7 +327,7 @@ pub fn test_fgets_getc_2() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -476,7 +476,7 @@ pub fn test_fgets_size_one_and_error_flag_3() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -542,7 +542,7 @@ pub fn test_freopen_4() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -623,7 +623,7 @@ pub fn test_fseeko_5() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -702,7 +702,7 @@ pub fn test_rename_6() {
} == -1_i32)
);
assert!(
(match nix::unistd::unlink(to.to_rust_string().as_str()) {
(match to.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -738,7 +738,7 @@ pub fn test_setvbuf_7() {
} == 0)
);
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/refcount/sys_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn test_stat_0() {
);
assert!(({ ({ (*st.borrow()).st_size } == (5 as ::libc::off_t)) }));
assert!(((field_ptr!(st.as_pointer(), st_mtime).read()) > (0 as ::libc::time_t)));
match nix::unistd::unlink(path.to_rust_string().as_str()) {
match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn test_fstat_1() {
__r
} == 0)
);
match nix::unistd::unlink(path.to_rust_string().as_str()) {
match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main_0() -> i32 {
);
assert!((FdRegistry::close(fd) == 0));
assert!(
(match nix::unistd::unlink(path.to_rust_string().as_str()) {
(match path.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
Expand Down
77 changes: 77 additions & 0 deletions tests/unit/out/refcount/unlink_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
extern crate libcc2rs;
use libcc2rs::*;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::{Read, Seek, Write};
use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn main() {
__cpp2rust_init_globals();
libcc2rs::cpp2rust_exit(main_0());
}
fn main_0() -> i32 {
let mut sibling: Ptr<i8> = Ptr::<i8>::from_string_literal(b"unlink-\xef\xbf\xbd.tmp");
let mut fp: Ptr<CFile> = match CFile::open(
&sibling.to_rust_string(),
&Ptr::<i8>::from_string_literal(b"wb").to_rust_string(),
) {
Some(__f) => Ptr::alloc(__f),
None => Ptr::null(),
};
assert!((!((fp).is_null())));
assert!(
(match Ptr::<i8>::from_string_literal(b"sentinel")
.with_c_bytes(|__bytes| fp.with_mut(|__f| __f.write(__bytes)) == __bytes.len())
{
true => 0,
false => -1,
} >= 0)
);
assert!(
({
let __r = fp.with(|__f| __f.close());
fp.delete();
__r
} == 0)
);
libcc2rs::cpp2rust_errno().write(0);
assert!(
(match Ptr::<i8>::from_string_literal(b"unlink-\xff.tmp")
.with_c_bytes(|__path| nix::unistd::unlink(__path))
{
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
-1
}
} == -1_i32)
);
assert!(((libcc2rs::cpp2rust_errno().read()) == libc::ENOENT));
fp = match CFile::open(
&sibling.to_rust_string(),
&Ptr::<i8>::from_string_literal(b"rb").to_rust_string(),
) {
Some(__f) => Ptr::alloc(__f),
None => Ptr::null(),
};
assert!((!((fp).is_null())));
assert!(
({
let __r = fp.with(|__f| __f.close());
fp.delete();
__r
} == 0)
);
assert!(
(match sibling.with_c_bytes(|__path| nix::unistd::unlink(__path)) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
-1
}
} == 0)
);
return 0;
}
pub fn __cpp2rust_init_globals() {}
31 changes: 31 additions & 0 deletions tests/unit/out/unsafe/unlink_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extern crate libc;
use libc::*;
extern crate libcc2rs;
use libcc2rs::*;
use std::collections::BTreeMap;
use std::io::{Read, Seek, Write};
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub fn main() {
unsafe {
__cpp2rust_init_globals();
libcc2rs::cpp2rust_exit(main_0() as i32);
}
}
unsafe fn main_0() -> i32 {
let mut sibling: *const libc::c_char =
(c"unlink-\xef\xbf\xbd.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(sibling, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((!((fp).is_null())));
assert!(((libc::fputs((c"sentinel".as_ptr().cast_mut()).cast_const(), fp)) >= (0)));
assert!(((libc::fclose(fp)) == (0)));
(*libcc2rs::cpp2rust_errno_unsafe()) = 0;
assert!(((libc::unlink((c"unlink-\xff.tmp".as_ptr().cast_mut()).cast_const())) == (-1_i32)));
assert!(((*libcc2rs::cpp2rust_errno_unsafe()) == (libc::ENOENT)));
fp = libc::fopen(sibling, (c"rb".as_ptr().cast_mut()).cast_const());
assert!((!((fp).is_null())));
assert!(((libc::fclose(fp)) == (0)));
assert!(((libc::unlink(sibling)) == (0)));
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
22 changes: 22 additions & 0 deletions tests/unit/unlink_bytes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>

int main(void) {
const char *sibling = "unlink-\xef\xbf\xbd.tmp";
FILE *fp = fopen(sibling, "wb");
assert(fp != NULL);
assert(fputs("sentinel", fp) >= 0);
assert(fclose(fp) == 0);

errno = 0;
assert(unlink("unlink-\xff.tmp") == -1);
assert(errno == ENOENT);
fp = fopen(sibling, "rb");
assert(fp != NULL);
assert(fclose(fp) == 0);

assert(unlink(sibling) == 0);
return 0;
}
Loading