|
| 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_errno_0() { |
| 10 | + (*libc::__errno_location()) = 0; |
| 11 | + assert!(((((*libc::__errno_location()) == (0)) as i32) != 0)); |
| 12 | + (*libc::__errno_location()) = 42; |
| 13 | + assert!(((((*libc::__errno_location()) == (42)) as i32) != 0)); |
| 14 | + let mut saved: i32 = (*libc::__errno_location()); |
| 15 | + assert!(((((saved) == (42)) as i32) != 0)); |
| 16 | + (*libc::__errno_location()) = 0; |
| 17 | +} |
| 18 | +pub unsafe fn test_errno_preserved_across_strdup_1() { |
| 19 | + (*libc::__errno_location()) = 99; |
| 20 | + let mut d: *mut u8 = |
| 21 | + libc::strdup((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8) as *mut u8; |
| 22 | + assert!((((!((d).is_null())) as i32) != 0)); |
| 23 | + assert!(((((*libc::__errno_location()) == (99)) as i32) != 0)); |
| 24 | + libc::free((d as *mut u8 as *mut ::libc::c_void)); |
| 25 | + (*libc::__errno_location()) = 0; |
| 26 | +} |
| 27 | +pub unsafe fn test_errno_from_fseek_2() { |
| 28 | + (*libc::__errno_location()) = 0; |
| 29 | + let mut r: i32 = if (match 0 { |
| 30 | + 0 => (*libcc2rs::cin_unsafe()).seek(std::io::SeekFrom::Start(0_i64 as u64)), |
| 31 | + 1 => (*libcc2rs::cin_unsafe()).seek(std::io::SeekFrom::Current(0_i64)), |
| 32 | + 2 => (*libcc2rs::cin_unsafe()).seek(std::io::SeekFrom::End(0_i64)), |
| 33 | + _ => Err(std::io::Error::other("unsupported whence for fseek.")), |
| 34 | + }) |
| 35 | + .is_ok() |
| 36 | + { |
| 37 | + 0 |
| 38 | + } else { |
| 39 | + -1 |
| 40 | + }; |
| 41 | + assert!(((((r) == (-1_i32)) as i32) != 0)); |
| 42 | + assert!(((((*libc::__errno_location()) == (29)) as i32) != 0)); |
| 43 | + (*libc::__errno_location()) = 0; |
| 44 | +} |
| 45 | +pub fn main() { |
| 46 | + unsafe { |
| 47 | + std::process::exit(main_0() as i32); |
| 48 | + } |
| 49 | +} |
| 50 | +unsafe fn main_0() -> i32 { |
| 51 | + (unsafe { test_errno_0() }); |
| 52 | + (unsafe { test_errno_preserved_across_strdup_1() }); |
| 53 | + (unsafe { test_errno_from_fseek_2() }); |
| 54 | + return 0; |
| 55 | +} |
0 commit comments