|
| 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 | +thread_local!( |
| 10 | + pub static data_0: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::new([0_u8, 127_u8, 255_u8]))); |
| 11 | +); |
| 12 | +pub fn check_1(s: Ptr<Vec<i8>>) { |
| 13 | + assert!(({ ({ ((*s.upgrade().deref()).len() - 1) } == { ::std::mem::size_of::<[u8; 3]>() }) })); |
| 14 | + let mut i: u32 = 0_u32; |
| 15 | + 'loop_: while ((i as usize) < ::std::mem::size_of::<[u8; 3]>()) { |
| 16 | + assert!( |
| 17 | + ({ (((index!(s, (i as usize)).read()) as u8) as i32) } == { |
| 18 | + (({ |
| 19 | + let __idx0 = (i) as usize; |
| 20 | + data_0.with(|rc| rc.borrow()[__idx0]) |
| 21 | + }) as i32) |
| 22 | + }) |
| 23 | + ); |
| 24 | + i.prefix_inc(); |
| 25 | + } |
| 26 | +} |
| 27 | +pub fn main() { |
| 28 | + __cpp2rust_init_globals(); |
| 29 | + std::process::exit(main_0()); |
| 30 | +} |
| 31 | +fn main_0() -> i32 { |
| 32 | + let file: Value<Box<[i8]>> = Rc::new(RefCell::new(i8::array_from_literal( |
| 33 | + b"test_stdcopy_istream.txt\0", |
| 34 | + ))); |
| 35 | + let mut fd: i32 = { |
| 36 | + let __mode = match Box::<[VaArg]>::from([(384).into()]).first() { |
| 37 | + Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), |
| 38 | + None => nix::sys::stat::Mode::empty(), |
| 39 | + }; |
| 40 | + match nix::fcntl::open( |
| 41 | + (file.as_pointer() as Ptr<i8>).to_rust_string().as_str(), |
| 42 | + nix::fcntl::OFlag::from_bits_retain( |
| 43 | + ((::libc::O_WRONLY | ::libc::O_CREAT) | ::libc::O_TRUNC), |
| 44 | + ), |
| 45 | + __mode, |
| 46 | + ) { |
| 47 | + Ok(__ofd) => FdRegistry::register(__ofd), |
| 48 | + Err(__e) => { |
| 49 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 50 | + -1 |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + assert!((fd >= 0)); |
| 55 | + assert!( |
| 56 | + ((match FdRegistry::with_fd(fd, |__fd| { |
| 57 | + ((data_0.with(|v| v.as_pointer()) as Ptr<u8>) as Ptr<u8>) |
| 58 | + .to_any() |
| 59 | + .reinterpret_cast::<u8>() |
| 60 | + .with_slice(::std::mem::size_of::<[u8; 3]>(), |__buf| { |
| 61 | + nix::unistd::write(__fd, __buf) |
| 62 | + }) |
| 63 | + }) { |
| 64 | + Ok(__n) => __n as isize, |
| 65 | + Err(__e) => { |
| 66 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 67 | + -1 |
| 68 | + } |
| 69 | + } as usize) |
| 70 | + == ::std::mem::size_of::<[u8; 3]>()) |
| 71 | + ); |
| 72 | + assert!((FdRegistry::close(fd) == 0)); |
| 73 | + { |
| 74 | + let f: Value<libcc2rs::CppStream> = Rc::new(RefCell::new( |
| 75 | + ::std::fs::File::open((file.as_pointer() as Ptr<i8>).to_string()) |
| 76 | + .map(libcc2rs::CppStream::from) |
| 77 | + .expect("Failed to open file"), |
| 78 | + )); |
| 79 | + let s: Value<Vec<i8>> = Rc::new(RefCell::new({ |
| 80 | + use std::io::Read; |
| 81 | + let mut __bytes: Vec<u8> = Vec::new(); |
| 82 | + (f.as_pointer()) |
| 83 | + .with_mut(|__f| __f.read_to_end(&mut __bytes)) |
| 84 | + .expect("couldn't read the file"); |
| 85 | + __bytes.push(0); |
| 86 | + CChar::from_byte_vec(__bytes) |
| 87 | + })); |
| 88 | + ({ check_1(s.as_pointer()) }); |
| 89 | + } |
| 90 | + { |
| 91 | + let f: Value<libcc2rs::CppStream> = Rc::new(RefCell::new( |
| 92 | + ::std::fs::File::open((file.as_pointer() as Ptr<i8>).to_string()) |
| 93 | + .map(libcc2rs::CppStream::from) |
| 94 | + .expect("Failed to open file"), |
| 95 | + )); |
| 96 | + let mut begin: Ptr<libcc2rs::CppStream> = f.as_pointer(); |
| 97 | + let mut copy: Ptr<libcc2rs::CppStream> = (begin).clone(); |
| 98 | + let mut end: Ptr<libcc2rs::CppStream> = Ptr::null(); |
| 99 | + let s: Value<Vec<i8>> = Rc::new(RefCell::new({ |
| 100 | + use std::io::Read; |
| 101 | + let mut __bytes: Vec<u8> = Vec::new(); |
| 102 | + (copy) |
| 103 | + .clone() |
| 104 | + .with_mut(|__f| __f.read_to_end(&mut __bytes)) |
| 105 | + .expect("couldn't read the file"); |
| 106 | + __bytes.push(0); |
| 107 | + CChar::from_byte_vec(__bytes) |
| 108 | + })); |
| 109 | + ({ check_1(s.as_pointer()) }); |
| 110 | + } |
| 111 | + match nix::unistd::unlink((file.as_pointer() as Ptr<i8>).to_rust_string().as_str()) { |
| 112 | + Ok(()) => 0, |
| 113 | + Err(__e) => { |
| 114 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 115 | + -1 |
| 116 | + } |
| 117 | + }; |
| 118 | + return 0; |
| 119 | +} |
| 120 | +pub fn __cpp2rust_init_globals() { |
| 121 | + let _ = data_0.with(|_| ()); |
| 122 | +} |
0 commit comments