Skip to content

Commit

Permalink
Use libc specific type for architecture specific ioctl defines on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-vri-es committed Nov 17, 2021
1 parent 83ffbee commit 15f2b0d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 28 deletions.
9 changes: 9 additions & 0 deletions libc-test/build.rs
Expand Up @@ -2740,6 +2740,9 @@ fn test_linux(target: &str) {
| "Elf64_Shdr" | "Elf32_Sym" | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr"
| "Elf32_Chdr" | "Elf64_Chdr" => ty.to_string(),

"Ioctl" if gnu => "unsigned long".to_string(),
"Ioctl" => "int".to_string(),

t if is_union => format!("union {}", t),

t if t.ends_with("_t") => t.to_string(),
Expand Down Expand Up @@ -2797,6 +2800,9 @@ fn test_linux(target: &str) {
// on Linux, this is a volatile int
"pthread_spinlock_t" => true,

// For internal use only, to define architecture specific ioctl constants with a libc specific type.
"Ioctl" => true,

_ => false,
}
});
Expand Down Expand Up @@ -3227,6 +3233,7 @@ fn test_linux(target: &str) {
// This function tests APIs that are incompatible to test when other APIs
// are included (e.g. because including both sets of headers clashes)
fn test_linux_like_apis(target: &str) {
let gnu = target.contains("gnu");
let musl = target.contains("musl");
let linux = target.contains("linux");
let emscripten = target.contains("emscripten");
Expand Down Expand Up @@ -3293,6 +3300,8 @@ fn test_linux_like_apis(target: &str) {
})
.skip_struct(|s| s != "termios2")
.type_name(move |ty, is_struct, is_union| match ty {
"Ioctl" if gnu => "unsigned long".to_string(),
"Ioctl" => "int".to_string(),
t if is_struct => format!("struct {}", t),
t if is_union => format!("union {}", t),
t => t.to_string(),
Expand Down
16 changes: 8 additions & 8 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Expand Up @@ -112,14 +112,14 @@ cfg_if! {
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;

pub const TIOCMGET: ::c_ulong = 0x5415;
pub const TIOCMBIS: ::c_ulong = 0x5416;
pub const TIOCMBIC: ::c_ulong = 0x5417;
pub const TIOCMSET: ::c_ulong = 0x5418;
pub const TCGETS2: ::c_ulong = 0x802c542a;
pub const TCSETS2: ::c_ulong = 0x402c542b;
pub const TCSETSW2: ::c_ulong = 0x402c542c;
pub const TCSETSF2: ::c_ulong = 0x402c542d;
pub const TIOCMGET: ::Ioctl = 0x5415;
pub const TIOCMBIS: ::Ioctl = 0x5416;
pub const TIOCMBIC: ::Ioctl = 0x5417;
pub const TIOCMSET: ::Ioctl = 0x5418;
pub const TCGETS2: ::Ioctl = 0x802c542a;
pub const TCSETS2: ::Ioctl = 0x402c542b;
pub const TCSETSW2: ::Ioctl = 0x402c542c;
pub const TCSETSF2: ::Ioctl = 0x402c542d;

pub const TIOCM_LE: ::c_int = 0x001;
pub const TIOCM_DTR: ::c_int = 0x002;
Expand Down
16 changes: 8 additions & 8 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Expand Up @@ -108,14 +108,14 @@ pub const SO_TIMESTAMPING: ::c_int = 37;
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;

pub const TIOCMGET: ::c_ulong = 0x741d;
pub const TIOCMBIS: ::c_ulong = 0x741b;
pub const TIOCMBIC: ::c_ulong = 0x741c;
pub const TIOCMSET: ::c_ulong = 0x741a;
pub const TCGETS2: ::c_ulong = 0x4030542a;
pub const TCSETS2: ::c_ulong = 0x8030542b;
pub const TCSETSW2: ::c_ulong = 0x8030542c;
pub const TCSETSF2: ::c_ulong = 0x8030542d;
pub const TIOCMGET: ::Ioctl = 0x741d;
pub const TIOCMBIS: ::Ioctl = 0x741b;
pub const TIOCMBIC: ::Ioctl = 0x741c;
pub const TIOCMSET: ::Ioctl = 0x741a;
pub const TCGETS2: ::Ioctl = 0x4030542a;
pub const TCSETS2: ::Ioctl = 0x8030542b;
pub const TCSETSW2: ::Ioctl = 0x8030542c;
pub const TCSETSF2: ::Ioctl = 0x8030542d;

pub const TIOCM_LE: ::c_int = 0x001;
pub const TIOCM_DTR: ::c_int = 0x002;
Expand Down
8 changes: 4 additions & 4 deletions src/unix/linux_like/linux/arch/powerpc/mod.rs
Expand Up @@ -90,10 +90,10 @@ pub const SO_BINDTOIFINDEX: ::c_int = 62;
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;

pub const TIOCMGET: ::c_int = 0x5415;
pub const TIOCMBIS: ::c_int = 0x5416;
pub const TIOCMBIC: ::c_int = 0x5417;
pub const TIOCMSET: ::c_int = 0x5418;
pub const TIOCMGET: ::Ioctl = 0x5415;
pub const TIOCMBIS: ::Ioctl = 0x5416;
pub const TIOCMBIC: ::Ioctl = 0x5417;
pub const TIOCMSET: ::Ioctl = 0x5418;

pub const TIOCM_LE: ::c_int = 0x001;
pub const TIOCM_DTR: ::c_int = 0x002;
Expand Down
16 changes: 8 additions & 8 deletions src/unix/linux_like/linux/arch/sparc/mod.rs
Expand Up @@ -100,14 +100,14 @@ pub const SO_TIMESTAMPING: ::c_int = 0x0023;
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;

pub const TIOCMGET: ::c_ulong = 0x4004746a;
pub const TIOCMBIS: ::c_ulong = 0x8004746c;
pub const TIOCMBIC: ::c_ulong = 0x8004746b;
pub const TIOCMSET: ::c_ulong = 0x8004746d;
pub const TCGETS2: ::c_ulong = 0x402c540c;
pub const TCSETS2: ::c_ulong = 0x802c540d;
pub const TCSETSW2: ::c_ulong = 0x802c540e;
pub const TCSETSF2: ::c_ulong = 0x802c540f;
pub const TIOCMGET: ::Ioctl = 0x4004746a;
pub const TIOCMBIS: ::Ioctl = 0x8004746c;
pub const TIOCMBIC: ::Ioctl = 0x8004746b;
pub const TIOCMSET: ::Ioctl = 0x8004746d;
pub const TCGETS2: ::Ioctl = 0x402c540c;
pub const TCSETS2: ::Ioctl = 0x802c540d;
pub const TCSETSW2: ::Ioctl = 0x802c540e;
pub const TCSETSF2: ::Ioctl = 0x802c540f;

pub const TIOCM_LE: ::c_int = 0x001;
pub const TIOCM_DTR: ::c_int = 0x002;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Expand Up @@ -4,6 +4,10 @@ pub type __rlimit_resource_t = ::c_uint;
pub type Lmid_t = ::c_long;
pub type regoff_t = ::c_int;

// Used in `linux::arch` to define ioctl constants.
#[doc(hidden)]
pub type Ioctl = ::c_ulong;

s! {
pub struct statx {
pub stx_mask: u32,
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Expand Up @@ -24,6 +24,10 @@ pub type rlim_t = ::c_ulonglong;

pub type flock64 = flock;

// Used in `linux::arch` to define ioctl constants.
#[doc(hidden)]
pub type Ioctl = ::c_int;

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut ::c_void {
#[repr(C)]
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/uclibc/mod.rs
Expand Up @@ -5,6 +5,10 @@ pub type regoff_t = ::c_int;
pub type __rlimit_resource_t = ::c_uint;
pub type __priority_which_t = ::c_uint;

// Used in `linux::arch` to define ioctl constants.
#[doc(hidden)]
pub type Ioctl = ::c_int;

s! {
pub struct statvfs { // Different than GNU!
pub f_bsize: ::c_ulong,
Expand Down

0 comments on commit 15f2b0d

Please sign in to comment.