Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 29, 2021

Conversation

CmdrMoozy
Copy link
Contributor

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

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
Copy link
Owner

LGTM; thanks for adding the inline comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants