Function v4l::v4l2::api::munmap

source ·
pub unsafe fn munmap(start: *mut c_void, length: usize) -> Result<()>
Expand description

A convenience wrapper around v4l2_munmap.

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

§Arguments

  • start - Starting address of the mapping
  • length - Length of the mapped region

§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);
        if let Ok(mapping) = mapping {
            v4l2::munmap(mapping, mapping_length).unwrap();
        }
    }
    v4l2::close(fd).unwrap();
}