Function v4l::v4l2::api::mmap

source ·
pub unsafe fn mmap(
    start: *mut c_void,
    length: usize,
    prot: c_int,
    flags: c_int,
    fd: c_int,
    offset: off_t,
) -> Result<*mut c_void>
Expand description

A convenience wrapper around v4l2_mmap.

In case of errors, the last OS error will be reported, aka errno on Linux.

§Arguments

  • start - Starting address of the new mapping, usually NULL
  • length - Length of the mapped region
  • prot - Desired memory protection of the mapped region
  • flags - Mapping flags
  • fd - File descriptor representing an opened device
  • offset - Offset in the source region, usually 0

§Safety

Start must be a raw pointer. Thus, the entire function is unsafe.

§Example

extern crate v4l;

use std::ptr;
use v4l::v4l2;

let fd = v4l2::open("/dev/video0", libc::O_RDWR);
if let Ok(fd) = fd {
    /* VIDIOC_REQBUFS */
    /* VIDIOC_QUERYBUF */
    let mapping_length: usize = 1000;

    unsafe {
        let mapping = v4l2::mmap(ptr::null_mut(), mapping_length,
                                 libc::PROT_READ | libc::PROT_WRITE,
                                 libc::MAP_SHARED, fd, 0);
    }
    v4l2::close(fd).unwrap();
}