diff --git a/rules/unistd/tgt_refcount.rs b/rules/unistd/tgt_refcount.rs index 1af45b5f63..40260dc31b 100644 --- a/rules/unistd/tgt_refcount.rs +++ b/rules/unistd/tgt_refcount.rs @@ -37,7 +37,7 @@ fn f3(a0: i32, a1: AnyPtr, a2: usize) -> isize { } fn f4(a0: Ptr) -> 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); diff --git a/tests/unit/out/refcount/fd_io.rs b/tests/unit/out/refcount/fd_io.rs index b5a3377640..57dcae5b61 100644 --- a/tests/unit/out/refcount/fd_io.rs +++ b/tests/unit/out/refcount/fd_io.rs @@ -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); diff --git a/tests/unit/out/refcount/fstat.rs b/tests/unit/out/refcount/fstat.rs index 61b56451aa..d248307f8b 100644 --- a/tests/unit/out/refcount/fstat.rs +++ b/tests/unit/out/refcount/fstat.rs @@ -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); diff --git a/tests/unit/out/refcount/isatty.rs b/tests/unit/out/refcount/isatty.rs index 7feff75475..b99935eb06 100644 --- a/tests/unit/out/refcount/isatty.rs +++ b/tests/unit/out/refcount/isatty.rs @@ -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); diff --git a/tests/unit/out/refcount/lseek_ftruncate.rs b/tests/unit/out/refcount/lseek_ftruncate.rs index 46c4c55a66..84a24cd75e 100644 --- a/tests/unit/out/refcount/lseek_ftruncate.rs +++ b/tests/unit/out/refcount/lseek_ftruncate.rs @@ -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); diff --git a/tests/unit/out/refcount/socket_unix_name.rs b/tests/unit/out/refcount/socket_unix_name.rs index 3193591af2..3771c19043 100644 --- a/tests/unit/out/refcount/socket_unix_name.rs +++ b/tests/unit/out/refcount/socket_unix_name.rs @@ -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); diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index a73f3d4416..007909d4f3 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -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); diff --git a/tests/unit/out/refcount/stdio.rs b/tests/unit/out/refcount/stdio.rs index 4a790f3951..02690306c0 100644 --- a/tests/unit/out/refcount/stdio.rs +++ b/tests/unit/out/refcount/stdio.rs @@ -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); diff --git a/tests/unit/out/refcount/stdio_nofd.rs b/tests/unit/out/refcount/stdio_nofd.rs index 1f2b0334d6..36d03a036b 100644 --- a/tests/unit/out/refcount/stdio_nofd.rs +++ b/tests/unit/out/refcount/stdio_nofd.rs @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/tests/unit/out/refcount/sys_stat.rs b/tests/unit/out/refcount/sys_stat.rs index 85a989f8b3..154ea10988 100644 --- a/tests/unit/out/refcount/sys_stat.rs +++ b/tests/unit/out/refcount/sys_stat.rs @@ -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); @@ -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); diff --git a/tests/unit/out/refcount/termios.rs b/tests/unit/out/refcount/termios.rs index f8de25daa5..38b4c08e82 100644 --- a/tests/unit/out/refcount/termios.rs +++ b/tests/unit/out/refcount/termios.rs @@ -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); diff --git a/tests/unit/out/refcount/unlink_bytes.rs b/tests/unit/out/refcount/unlink_bytes.rs new file mode 100644 index 0000000000..859c329f47 --- /dev/null +++ b/tests/unit/out/refcount/unlink_bytes.rs @@ -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 = Ptr::::from_string_literal(b"unlink-\xef\xbf\xbd.tmp"); + let mut fp: Ptr = match CFile::open( + &sibling.to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), + ) { + Some(__f) => Ptr::alloc(__f), + None => Ptr::null(), + }; + assert!((!((fp).is_null()))); + assert!( + (match Ptr::::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::::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::::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() {} diff --git a/tests/unit/out/unsafe/unlink_bytes.rs b/tests/unit/out/unsafe/unlink_bytes.rs new file mode 100644 index 0000000000..c49ec24d5b --- /dev/null +++ b/tests/unit/out/unsafe/unlink_bytes.rs @@ -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() {} diff --git a/tests/unit/unlink_bytes.c b/tests/unit/unlink_bytes.c new file mode 100644 index 0000000000..b03cb80886 --- /dev/null +++ b/tests/unit/unlink_bytes.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +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; +}