|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +pub fn main() { |
| 10 | + std::process::exit(main_0()); |
| 11 | +} |
| 12 | +fn main_0() -> i32 { |
| 13 | + let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal( |
| 14 | + b"/tmp/cpp2rust_fstat_test.tmp", |
| 15 | + ))); |
| 16 | + let fd: Value<i32> = Rc::new(RefCell::new({ |
| 17 | + let __mode = match &[(420).into()].first() { |
| 18 | + Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), |
| 19 | + None => nix::sys::stat::Mode::empty(), |
| 20 | + }; |
| 21 | + match nix::fcntl::open( |
| 22 | + (*path.borrow()).to_rust_string().as_str(), |
| 23 | + nix::fcntl::OFlag::from_bits_retain( |
| 24 | + ((::libc::O_RDWR | ::libc::O_CREAT) | ::libc::O_TRUNC), |
| 25 | + ), |
| 26 | + __mode, |
| 27 | + ) { |
| 28 | + Ok(__ofd) => FdRegistry::register(__ofd), |
| 29 | + Err(__e) => { |
| 30 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 31 | + -1 |
| 32 | + } |
| 33 | + } |
| 34 | + })); |
| 35 | + assert!(((((*fd.borrow()) >= 0) as i32) != 0)); |
| 36 | + assert!( |
| 37 | + (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { |
| 38 | + Ptr::from_string_literal(b"hello") |
| 39 | + .to_any() |
| 40 | + .reinterpret_cast::<u8>() |
| 41 | + .with_slice(5_usize, |__buf| nix::unistd::write(__fd, __buf)) |
| 42 | + }) { |
| 43 | + Ok(__n) => __n as isize, |
| 44 | + Err(__e) => { |
| 45 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 46 | + -1 |
| 47 | + } |
| 48 | + } == 5_isize) as i32) |
| 49 | + != 0) |
| 50 | + ); |
| 51 | + let st: Value<libcc2rs::Stat> = Rc::new(RefCell::new(Default::default())); |
| 52 | + assert!( |
| 53 | + (((match FdRegistry::with_fd((*fd.borrow()), |__fd| nix::sys::stat::fstat(__fd)) { |
| 54 | + Ok(__s) => { |
| 55 | + (st.as_pointer()).with_mut(|__st| *__st = Stat::from_libc(&__s)); |
| 56 | + 0 |
| 57 | + } |
| 58 | + Err(__e) => { |
| 59 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 60 | + -1 |
| 61 | + } |
| 62 | + } == 0) as i32) |
| 63 | + != 0) |
| 64 | + ); |
| 65 | + assert!(((((*(*st.borrow()).st_size.borrow()) == 5_i64) as i32) != 0)); |
| 66 | + assert!((((((*(*st.borrow()).st_mode.borrow()) & 61440_u32) == 32768_u32) as i32) != 0)); |
| 67 | + assert!((((FdRegistry::close((*fd.borrow())) == 0) as i32) != 0)); |
| 68 | + assert!( |
| 69 | + (((match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { |
| 70 | + Ok(()) => 0, |
| 71 | + Err(__e) => { |
| 72 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 73 | + -1 |
| 74 | + } |
| 75 | + } == 0) as i32) |
| 76 | + != 0) |
| 77 | + ); |
| 78 | + return 0; |
| 79 | +} |
0 commit comments