Here's some code I generated using c2rust and then cleaned up a bit:
#![feature(libc)]
extern crate libc;
use libc::*;
use std::mem::transmute;
extern "C" {
#[no_mangle]
fn read(__fd: c_int, __buf: *mut c_void, __nbytes: c_ulong) -> c_long;
#[no_mangle]
fn mmap(
__addr: *mut c_void,
__len: c_ulong,
__prot: c_int,
__flags: c_int,
__fd: c_int,
__offset: c_long,
) -> *mut c_void;
}
pub fn main() {
unsafe {
let buf: *mut c_void = mmap(
0 as *mut c_void,
256i32 as c_ulong,
0x1i32 | 0x2i32 | 0x4i32,
0x2i32 | 0x20i32,
-1i32,
0i32 as c_long,
);
read(0i32, buf, 256i32 as c_ulong);
transmute::<*mut c_void, Option<unsafe extern "C" fn() -> ()>>(buf).unwrap()();
}
}
While I understand what it does, I'm not sure how to interpret the last expression. What does Option<unsafe extern "C" fn() -> ()>
mean?