|
| 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_fd_io_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(((1 | 64) | 512)), |
| 24 | + __mode, |
| 25 | + ) { |
| 26 | + Ok(__ofd) => FdRegistry::register(__ofd), |
| 27 | + Err(__e) => { |
| 28 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 29 | + -1 |
| 30 | + } |
| 31 | + } |
| 32 | + })); |
| 33 | + assert!(((((*fd.borrow()) >= 0) as i32) != 0)); |
| 34 | + assert!( |
| 35 | + (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { |
| 36 | + Ptr::from_string_literal(b"hello world") |
| 37 | + .to_any() |
| 38 | + .reinterpret_cast::<u8>() |
| 39 | + .with_slice(11_usize, |__buf| nix::unistd::write(__fd, __buf)) |
| 40 | + }) { |
| 41 | + Ok(__n) => __n as isize, |
| 42 | + Err(__e) => { |
| 43 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 44 | + -1 |
| 45 | + } |
| 46 | + } == 11_isize) as i32) |
| 47 | + != 0) |
| 48 | + ); |
| 49 | + assert!((((FdRegistry::close((*fd.borrow())) == 0) as i32) != 0)); |
| 50 | + (*fd.borrow_mut()) = { |
| 51 | + let __mode = match &[].first() { |
| 52 | + Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), |
| 53 | + None => nix::sys::stat::Mode::empty(), |
| 54 | + }; |
| 55 | + match nix::fcntl::open( |
| 56 | + (*path.borrow()).to_rust_string().as_str(), |
| 57 | + nix::fcntl::OFlag::from_bits_retain(0), |
| 58 | + __mode, |
| 59 | + ) { |
| 60 | + Ok(__ofd) => FdRegistry::register(__ofd), |
| 61 | + Err(__e) => { |
| 62 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 63 | + -1 |
| 64 | + } |
| 65 | + } |
| 66 | + }; |
| 67 | + assert!(((((*fd.borrow()) >= 0) as i32) != 0)); |
| 68 | + let buf: Value<Box<[u8]>> = Rc::new(RefCell::new( |
| 69 | + (0..16).map(|_| <u8>::default()).collect::<Box<[u8]>>(), |
| 70 | + )); |
| 71 | + { |
| 72 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>) |
| 73 | + .to_any() |
| 74 | + .memset((0) as u8, ::std::mem::size_of::<[u8; 16]>() as usize); |
| 75 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any().clone() |
| 76 | + }; |
| 77 | + assert!( |
| 78 | + (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { |
| 79 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>) |
| 80 | + .to_any() |
| 81 | + .reinterpret_cast::<u8>() |
| 82 | + .with_slice_mut(::std::mem::size_of::<[u8; 16]>(), |__buf| { |
| 83 | + nix::unistd::read(__fd, __buf) |
| 84 | + }) |
| 85 | + }) { |
| 86 | + Ok(__n) => __n as isize, |
| 87 | + Err(__e) => { |
| 88 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 89 | + -1 |
| 90 | + } |
| 91 | + } == 11_isize) as i32) |
| 92 | + != 0) |
| 93 | + ); |
| 94 | + assert!( |
| 95 | + ((({ |
| 96 | + let mut __it1 = (buf.as_pointer() as Ptr<u8>).to_c_string_iterator(); |
| 97 | + let mut __it2 = Ptr::from_string_literal(b"hello world").to_c_string_iterator(); |
| 98 | + loop { |
| 99 | + let __c1 = __it1.next(); |
| 100 | + let __c2 = __it2.next(); |
| 101 | + if __c1 != __c2 { |
| 102 | + break (__c1.unwrap_or(0) as i32) - (__c2.unwrap_or(0) as i32); |
| 103 | + } |
| 104 | + if __c1.is_none() { |
| 105 | + break 0; |
| 106 | + } |
| 107 | + } |
| 108 | + } == 0) as i32) |
| 109 | + != 0) |
| 110 | + ); |
| 111 | + assert!( |
| 112 | + (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { |
| 113 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>) |
| 114 | + .to_any() |
| 115 | + .reinterpret_cast::<u8>() |
| 116 | + .with_slice_mut(::std::mem::size_of::<[u8; 16]>(), |__buf| { |
| 117 | + nix::unistd::read(__fd, __buf) |
| 118 | + }) |
| 119 | + }) { |
| 120 | + Ok(__n) => __n as isize, |
| 121 | + Err(__e) => { |
| 122 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 123 | + -1 |
| 124 | + } |
| 125 | + } == 0_isize) as i32) |
| 126 | + != 0) |
| 127 | + ); |
| 128 | + assert!((((FdRegistry::close((*fd.borrow())) == 0) as i32) != 0)); |
| 129 | + assert!( |
| 130 | + (((match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { |
| 131 | + Ok(()) => 0, |
| 132 | + Err(__e) => { |
| 133 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 134 | + -1 |
| 135 | + } |
| 136 | + } == 0) as i32) |
| 137 | + != 0) |
| 138 | + ); |
| 139 | + return 0; |
| 140 | +} |
0 commit comments