ioctl_id/lib.rs
1//! Provides constant functions to compute for `ioctl(2)` identifiers.
2//!
3//! Currently, this supports Linux and macOS. The long term goal is to support `ioctl` identifiers for other BSD
4//! variants.
5//!
6//! ## Usage Notes
7//! [`IoctlId`] is an alias for the type to pass into the `ioctl(2)` request. This is either a `u32` or `u64`, depending
8//! on the target OS and architecture.
9//!
10//! The [`io()`], [`ior()`], [`iow()`], and [`iowr()`] functions take a type parameter, similar to the `_IO()`,
11//! `_IOR()`, `_IOW()`, and `_IOWR()` macros.
12//!
13//! For example, the following C code:
14//! ```c
15//! struct my_ioctl_data {
16//! unsigned int a;
17//! };
18//!
19//! #define MY_IOCTL _IOR(0x12, 0x34, struct my_ioctl_data)
20//! ```
21//!
22//! Would be written in Rust as:
23//! ```rust
24//! use ioctl_id::*;
25//!
26//! #[repr(C)]
27//! struct MyIoctlData {
28//! a: u32,
29//! }
30//!
31//! const MY_IOCTL: IoctlId = ior::<MyIoctlData>(0x12, 0x34);
32//! ```
33#![no_std]
34#![warn(missing_docs)]
35
36#[cfg(target_os = "linux")]
37mod linux;
38
39#[cfg(target_os = "linux")]
40pub use linux::*;
41
42#[cfg(target_os = "macos")]
43mod macos;
44
45#[cfg(target_os = "macos")]
46pub use macos::*;
47
48#[cfg(all(
49 test,
50 target_os = "linux",
51 not(any(
52 target_arch = "mips",
53 target_arch = "mips64",
54 target_arch = "mips64r6",
55 target_arch = "powerpc",
56 target_arch = "sparc",
57 target_arch = "sparc64"
58 ))
59))]
60mod ccompat_tests_linux_generic;
61
62#[cfg(all(test, target_os = "macos"))]
63mod ccompat_tests_macos;