Skip to content

Commit 6e71818

Browse files
committed
use rustix for _IO generator macros
this would use libc but for rust-lang/libc#1662
1 parent 30f6dba commit 6e71818

File tree

2 files changed

+6
-63
lines changed

2 files changed

+6
-63
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository= "https://github.com/raymanfx/libv4l-rs"
1111
[dependencies]
1212
bitflags = "2"
1313
libc = "0.2"
14+
rustix = "0.38.37"
1415
v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
1516
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }
1617

src/v4l2/vidioc.rs

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,28 @@
11
use crate::v4l_sys::*;
22

3-
#[cfg(not(target_env = "musl"))]
4-
#[allow(non_camel_case_types)]
5-
pub type _IOC_TYPE = std::os::raw::c_ulong;
6-
#[cfg(target_env = "musl")]
7-
#[allow(non_camel_case_types)]
8-
pub type _IOC_TYPE = std::os::raw::c_int;
9-
10-
// linux ioctl.h
11-
const _IOC_NRBITS: u8 = 8;
12-
const _IOC_TYPEBITS: u8 = 8;
13-
14-
const _IOC_SIZEBITS: u8 = 14;
15-
16-
const _IOC_NRSHIFT: u8 = 0;
17-
const _IOC_TYPESHIFT: u8 = _IOC_NRSHIFT + _IOC_NRBITS;
18-
const _IOC_SIZESHIFT: u8 = _IOC_TYPESHIFT + _IOC_TYPEBITS;
19-
const _IOC_DIRSHIFT: u8 = _IOC_SIZESHIFT + _IOC_SIZEBITS;
20-
21-
const _IOC_NONE: u8 = 0;
22-
23-
#[cfg(any(target_os = "linux", target_os = "android"))]
24-
const _IOC_WRITE: u8 = 1;
25-
#[cfg(target_os = "freebsd")]
26-
const _IOC_WRITE: u8 = 2;
27-
28-
#[cfg(any(target_os = "linux", target_os = "android"))]
29-
const _IOC_READ: u8 = 2;
30-
#[cfg(target_os = "freebsd")]
31-
const _IOC_READ: u8 = 1;
32-
33-
macro_rules! _IOC_TYPECHECK {
34-
($type:ty) => {
35-
std::mem::size_of::<$type>()
36-
};
37-
}
38-
39-
macro_rules! _IOC {
40-
($dir:expr, $type:expr, $nr:expr, $size:expr) => {
41-
(($dir as _IOC_TYPE) << $crate::v4l2::vidioc::_IOC_DIRSHIFT)
42-
| (($type as _IOC_TYPE) << $crate::v4l2::vidioc::_IOC_TYPESHIFT)
43-
| (($nr as _IOC_TYPE) << $crate::v4l2::vidioc::_IOC_NRSHIFT)
44-
| (($size as _IOC_TYPE) << $crate::v4l2::vidioc::_IOC_SIZESHIFT)
45-
};
46-
}
3+
pub type _IOC_TYPE = rustix::ioctl::Opcode;
474

485
macro_rules! _IO {
496
($type:expr, $nr:expr) => {
50-
_IOC!($crate::v4l2::vidioc::_IOC_NONE, $type, $nr, 0)
7+
rustix::ioctl::Opcode::none::<()>($type, $nr)
518
};
529
}
5310

5411
macro_rules! _IOR {
5512
($type:expr, $nr:expr, $size:ty) => {
56-
_IOC!(
57-
$crate::v4l2::vidioc::_IOC_READ,
58-
$type,
59-
$nr,
60-
_IOC_TYPECHECK!($size)
61-
)
13+
rustix::ioctl::Opcode::read::<$size>($type, $nr)
6214
};
6315
}
6416

6517
macro_rules! _IOW {
6618
($type:expr, $nr:expr, $size:ty) => {
67-
_IOC!(
68-
$crate::v4l2::vidioc::_IOC_WRITE,
69-
$type,
70-
$nr,
71-
_IOC_TYPECHECK!($size)
72-
)
19+
rustix::ioctl::Opcode::write::<$size>($type, $nr)
7320
};
7421
}
7522

7623
macro_rules! _IOWR {
7724
($type:expr, $nr:expr, $size:ty) => {
78-
_IOC!(
79-
$crate::v4l2::vidioc::_IOC_READ | $crate::v4l2::vidioc::_IOC_WRITE,
80-
$type,
81-
$nr,
82-
_IOC_TYPECHECK!($size)
83-
)
25+
rustix::ioctl::Opcode::read_write::<$size>($type, $nr)
8426
};
8527
}
8628

0 commit comments

Comments
 (0)