Skip to content

Commit

Permalink
Add FreeBSD support (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmovchan authored Aug 8, 2024
1 parent 6d17141 commit 33817d4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/v4l2/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod detail {
pub unsafe fn close(fd: std::os::raw::c_int) -> std::os::raw::c_int {
libc::close(fd)
}
#[cfg(any(target_os = "linux", target_os = "android"))]
pub unsafe fn ioctl(
fd: std::os::raw::c_int,
request: vidioc::_IOC_TYPE,
Expand All @@ -80,6 +81,14 @@ mod detail {
*/
libc::syscall(libc::SYS_ioctl, fd, request, argp) as std::os::raw::c_int
}
#[cfg(target_os = "freebsd")]
pub unsafe fn ioctl(
fd: std::os::raw::c_int,
request: vidioc::_IOC_TYPE,
argp: *mut std::os::raw::c_void,
) -> std::os::raw::c_int {
libc::ioctl(fd, request, argp)
}
pub unsafe fn mmap(
start: *mut std::os::raw::c_void,
length: usize,
Expand Down
8 changes: 8 additions & 0 deletions src/v4l2/vidioc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ const _IOC_SIZESHIFT: u8 = _IOC_TYPESHIFT + _IOC_TYPEBITS;
const _IOC_DIRSHIFT: u8 = _IOC_SIZESHIFT + _IOC_SIZEBITS;

const _IOC_NONE: u8 = 0;

#[cfg(any(target_os = "linux", target_os = "android"))]
const _IOC_WRITE: u8 = 1;
#[cfg(target_os = "freebsd")]
const _IOC_WRITE: u8 = 2;

#[cfg(any(target_os = "linux", target_os = "android"))]
const _IOC_READ: u8 = 2;
#[cfg(target_os = "freebsd")]
const _IOC_READ: u8 = 1;

macro_rules! _IOC_TYPECHECK {
($type:ty) => {
Expand Down
1 change: 1 addition & 0 deletions v4l2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build = "build.rs"

[build-dependencies]
bindgen = "0.69.1"
pkg-config = "0.3.30"
10 changes: 10 additions & 0 deletions v4l2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ use std::env;
use std::path::PathBuf;

fn main() {
let pkg_conf = pkg_config::Config::new()
.probe("libv4l2")
.expect("pkg-config has failed to find `libv4l2`");

let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_args(
pkg_conf
.include_paths
.into_iter()
.map(|path| format!("-I{}", path.to_string_lossy())),
)
.generate()
.expect("Failed to generate bindings");

Expand Down

0 comments on commit 33817d4

Please sign in to comment.