|
| 1 | +extern crate libc; |
| 2 | +use libc::*; |
| 3 | +extern crate libcc2rs; |
| 4 | +use libcc2rs::*; |
| 5 | +use std::collections::BTreeMap; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; |
| 8 | +use std::rc::Rc; |
| 9 | +pub unsafe fn test_fputc_0() { |
| 10 | + match (*libcc2rs::cout_unsafe()).write_all(&[('H' as i32) as u8]) { |
| 11 | + Ok(()) => ('H' as i32) & 0xff, |
| 12 | + Err(_) => -1, |
| 13 | + }; |
| 14 | + match (*libcc2rs::cout_unsafe()).write_all(&[('i' as i32) as u8]) { |
| 15 | + Ok(()) => ('i' as i32) & 0xff, |
| 16 | + Err(_) => -1, |
| 17 | + }; |
| 18 | + match (*libcc2rs::cout_unsafe()).write_all(&[('\n' as i32) as u8]) { |
| 19 | + Ok(()) => ('\n' as i32) & 0xff, |
| 20 | + Err(_) => -1, |
| 21 | + }; |
| 22 | +} |
| 23 | +pub unsafe fn test_fputs_1() { |
| 24 | + { |
| 25 | + let bytes = |
| 26 | + std::ffi::CStr::from_ptr((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8) |
| 27 | + .to_bytes(); |
| 28 | + match (*libcc2rs::cout_unsafe()).write_all(bytes) { |
| 29 | + Ok(()) => 0, |
| 30 | + Err(_) => -1, |
| 31 | + } |
| 32 | + }; |
| 33 | + match (*libcc2rs::cout_unsafe()).write_all(&[('\n' as i32) as u8]) { |
| 34 | + Ok(()) => ('\n' as i32) & 0xff, |
| 35 | + Err(_) => -1, |
| 36 | + }; |
| 37 | + let mut s: *const u8 = (b"from variable\0".as_ptr().cast_mut()).cast_const(); |
| 38 | + { |
| 39 | + let bytes = std::ffi::CStr::from_ptr(s as *const i8).to_bytes(); |
| 40 | + match (*libcc2rs::cout_unsafe()).write_all(bytes) { |
| 41 | + Ok(()) => 0, |
| 42 | + Err(_) => -1, |
| 43 | + } |
| 44 | + }; |
| 45 | + match (*libcc2rs::cout_unsafe()).write_all(&[('\n' as i32) as u8]) { |
| 46 | + Ok(()) => ('\n' as i32) & 0xff, |
| 47 | + Err(_) => -1, |
| 48 | + }; |
| 49 | + let mut buf: [u8; 4] = [ |
| 50 | + (('b' as i32) as u8), |
| 51 | + (('u' as i32) as u8), |
| 52 | + (('f' as i32) as u8), |
| 53 | + (('\0' as i32) as u8), |
| 54 | + ]; |
| 55 | + { |
| 56 | + let bytes = |
| 57 | + std::ffi::CStr::from_ptr((buf.as_mut_ptr()).cast_const() as *const i8).to_bytes(); |
| 58 | + match (*libcc2rs::cout_unsafe()).write_all(bytes) { |
| 59 | + Ok(()) => 0, |
| 60 | + Err(_) => -1, |
| 61 | + } |
| 62 | + }; |
| 63 | + match (*libcc2rs::cout_unsafe()).write_all(&[('\n' as i32) as u8]) { |
| 64 | + Ok(()) => ('\n' as i32) & 0xff, |
| 65 | + Err(_) => -1, |
| 66 | + }; |
| 67 | +} |
| 68 | +pub fn main() { |
| 69 | + unsafe { |
| 70 | + std::process::exit(main_0() as i32); |
| 71 | + } |
| 72 | +} |
| 73 | +unsafe fn main_0() -> i32 { |
| 74 | + (unsafe { test_fputc_0() }); |
| 75 | + (unsafe { test_fputs_1() }); |
| 76 | + return 0; |
| 77 | +} |
0 commit comments