Skip to content
Merged
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
124 changes: 19 additions & 105 deletions tests/unit/out/unsafe/sys_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,124 +8,38 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn test_stat_0() {
let mut path: *const u8 = (b"/tmp/cpp2rust_stat_test.tmp\0".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::std::fs::File =
match std::ffi::CStr::from_ptr((b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8)
.to_str()
.expect("invalid c-string")
{
v if v == "rb" => std::fs::OpenOptions::new()
.read(true)
.open(
std::ffi::CStr::from_ptr(path as *const i8)
.to_str()
.expect("invalid c-string"),
)
.ok()
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),
v if v == "wb" => std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(
std::ffi::CStr::from_ptr(path as *const i8)
.to_str()
.expect("invalid c-string"),
)
.ok()
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),
_ => panic!("unsupported mode"),
};
let mut fp: *mut ::libc::FILE = libc::fopen(
path as *const i8,
(b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8,
);
assert!((((!((fp).is_null())) as i32) != 0));
{
let bytes =
std::ffi::CStr::from_ptr((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8)
.to_bytes();
match (*fp).write_all(bytes) {
Ok(()) => 0,
Err(_) => -1,
}
};
assert!(
(((({
Box::from_raw(fp);
0
}) == (0)) as i32)
!= 0)
libc::fputs(
(b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8,
fp,
);
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
let mut st: stat = std::mem::zeroed::<stat>();
assert!(((((libc::stat(path as *const i8, (&mut st as *mut stat))) == (0)) as i32) != 0));
assert!(((((st.st_size) == (5_i64)) as i32) != 0));
libc::unlink(path as *const i8);
}
pub unsafe fn test_fstat_1() {
let mut path: *const u8 = (b"/tmp/cpp2rust_fstat_test.tmp\0".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::std::fs::File =
match std::ffi::CStr::from_ptr((b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8)
.to_str()
.expect("invalid c-string")
{
v if v == "rb" => std::fs::OpenOptions::new()
.read(true)
.open(
std::ffi::CStr::from_ptr(path as *const i8)
.to_str()
.expect("invalid c-string"),
)
.ok()
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),
v if v == "wb" => std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(
std::ffi::CStr::from_ptr(path as *const i8)
.to_str()
.expect("invalid c-string"),
)
.ok()
.map_or(std::ptr::null_mut(), |f| Box::into_raw(Box::new(f))),
_ => panic!("unsupported mode"),
};
let mut fp: *mut ::libc::FILE = libc::fopen(
path as *const i8,
(b"wb\0".as_ptr().cast_mut()).cast_const() as *const i8,
);
assert!((((!((fp).is_null())) as i32) != 0));
{
let bytes = std::ffi::CStr::from_ptr(
(b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8
)
.to_bytes();
match (*fp).write_all(bytes) {
Ok(()) => 0,
Err(_) => -1,
}
};
if !(fp).is_null() {
match (*fp).sync_all() {
Ok(_) => 0,
Err(_) => -1,
}
} else {
::std::io::stdout().flush().unwrap();
::std::io::stderr().flush().unwrap();
0
};
let mut fd: i32 = if fp == libcc2rs::cin_unsafe() {
0
} else if fp == libcc2rs::cout_unsafe() {
1
} else if fp == libcc2rs::cerr_unsafe() {
2
} else {
::std::os::fd::AsRawFd::as_raw_fd(&*fp)
};
libc::fputs(
(b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8,
fp,
);
libc::fflush(fp);
let mut fd: i32 = libc::fileno(fp);
let mut st: stat = std::mem::zeroed::<stat>();
assert!(((((libc::fstat(fd, (&mut st as *mut stat))) == (0)) as i32) != 0));
assert!(((((st.st_size) == (11_i64)) as i32) != 0));
assert!(
(((({
Box::from_raw(fp);
0
}) == (0)) as i32)
!= 0)
);
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
libc::unlink(path as *const i8);
}
pub fn main() {
Expand Down
Loading