raymanfx / libv4l-rs

Video4Linux2 bindings for Rust
MIT License
145 stars 62 forks source link

v4l2: api: Fix ioctl() argument type mismatch. #34

Closed CmdrMoozy closed 3 years ago

CmdrMoozy commented 3 years ago

Annoyingly, the libc crate defines ioctl()'s argument types differently on different platforms. On x86_64-unknown-linux-gnu, the existing code works just fine. But, on aarch64-unknown-linux-musl (and Android apparently), the libc crate instead says it takes an int, so we get a compilation error.

We could work around this by writing the code differently for different targets with #[cfg()]. But, that's less than ideal.

So, hack around this by using syscall() instead. It's a variadic function, so we can just pass ~whatever~ into it. We're kind of depending on C's type conversion rules by doing so, but this turns out to be kind of how e.g. glibc does it anyway.

At the end of the day: this should "just work" on all targets.

Signed-off-by: Axel Rasmussen axelrasmussen@google.com

raymanfx commented 3 years ago

LGTM; thanks for adding the inline comment!