Advertisement
Guest User

f

a guest
Feb 27th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.99 KB | None | 0 0
  1. #![allow(
  2.     dead_code,
  3.     mutable_transmutes,
  4.     non_camel_case_types,
  5.     non_snake_case,
  6.     non_upper_case_globals,
  7.     unused_mut
  8. )]
  9. #![feature(libc)]
  10. extern crate libc;
  11. extern "C" {
  12.     #[no_mangle]
  13.     static mut stderr: *mut _IO_FILE;
  14.     #[no_mangle]
  15.     fn fclose(__stream: *mut FILE) -> libc::c_int;
  16.     #[no_mangle]
  17.     fn fopen(__filename: *const libc::c_char, __modes: *const libc::c_char) -> *mut FILE;
  18.     #[no_mangle]
  19.     fn fprintf(_: *mut FILE, _: *const libc::c_char, ...) -> libc::c_int;
  20.     #[no_mangle]
  21.     fn perror(__s: *const libc::c_char);
  22.     #[no_mangle]
  23.     fn __errno_location() -> *mut libc::c_int;
  24.     #[no_mangle]
  25.     fn strerror(_: libc::c_int) -> *mut libc::c_char;
  26. }
  27. pub type size_t = libc::c_ulong;
  28. pub type __off_t = libc::c_long;
  29. pub type __off64_t = libc::c_long;
  30. #[derive(Copy, Clone)]
  31. #[repr(C)]
  32. pub struct _IO_FILE {
  33.     pub _flags: libc::c_int,
  34.     pub _IO_read_ptr: *mut libc::c_char,
  35.     pub _IO_read_end: *mut libc::c_char,
  36.     pub _IO_read_base: *mut libc::c_char,
  37.     pub _IO_write_base: *mut libc::c_char,
  38.     pub _IO_write_ptr: *mut libc::c_char,
  39.     pub _IO_write_end: *mut libc::c_char,
  40.     pub _IO_buf_base: *mut libc::c_char,
  41.     pub _IO_buf_end: *mut libc::c_char,
  42.     pub _IO_save_base: *mut libc::c_char,
  43.     pub _IO_backup_base: *mut libc::c_char,
  44.     pub _IO_save_end: *mut libc::c_char,
  45.     pub _markers: *mut _IO_marker,
  46.     pub _chain: *mut _IO_FILE,
  47.     pub _fileno: libc::c_int,
  48.     pub _flags2: libc::c_int,
  49.     pub _old_offset: __off_t,
  50.     pub _cur_column: libc::c_ushort,
  51.     pub _vtable_offset: libc::c_schar,
  52.     pub _shortbuf: [libc::c_char; 1],
  53.     pub _lock: *mut libc::c_void,
  54.     pub _offset: __off64_t,
  55.     pub __pad1: *mut libc::c_void,
  56.     pub __pad2: *mut libc::c_void,
  57.     pub __pad3: *mut libc::c_void,
  58.     pub __pad4: *mut libc::c_void,
  59.     pub __pad5: size_t,
  60.     pub _mode: libc::c_int,
  61.     pub _unused2: [libc::c_char; 20],
  62. }
  63. pub type _IO_lock_t = ();
  64. #[derive(Copy, Clone)]
  65. #[repr(C)]
  66. pub struct _IO_marker {
  67.     pub _next: *mut _IO_marker,
  68.     pub _sbuf: *mut _IO_FILE,
  69.     pub _pos: libc::c_int,
  70. }
  71. pub type FILE = _IO_FILE;
  72. unsafe fn main_0() -> libc::c_int {
  73.     let mut pf: *mut FILE = 0 as *mut FILE;
  74.     let mut errnum: libc::c_int = 0;
  75.     pf = fopen(
  76.         b"unexist.txt\x00" as *const u8 as *const libc::c_char,
  77.         b"rb\x00" as *const u8 as *const libc::c_char,
  78.     );
  79.     if pf.is_null() {
  80.         errnum = *__errno_location();
  81.         fprintf(
  82.             stderr,
  83.             b"Value of errno: %d\n\x00" as *const u8 as *const libc::c_char,
  84.             *__errno_location(),
  85.         );
  86.         perror(b"Error printed by perror\x00" as *const u8 as *const libc::c_char);
  87.         fprintf(
  88.             stderr,
  89.             b"Error opening file: %s\n\x00" as *const u8 as *const libc::c_char,
  90.             strerror(errnum),
  91.         );
  92.     } else {
  93.         fclose(pf);
  94.     }
  95.     return 0i32;
  96. }
  97. pub fn main() {
  98.     unsafe { ::std::process::exit(main_0() as i32) }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement