Skip to content

Commit 7c95819

Browse files
committed
Use libc specific type for architecture specific ioctl defines on Linux.
1 parent 83ffbee commit 7c95819

File tree

8 files changed

+67
-28
lines changed

8 files changed

+67
-28
lines changed

libc-test/build.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,9 @@ fn test_linux(target: &str) {
27402740
| "Elf64_Shdr" | "Elf32_Sym" | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr"
27412741
| "Elf32_Chdr" | "Elf64_Chdr" => ty.to_string(),
27422742

2743+
"Ioctl" if gnu => "unsigned long".to_string(),
2744+
"Ioctl" => "int".to_string(),
2745+
27432746
t if is_union => format!("union {}", t),
27442747

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

2803+
// For internal use only, to define architecture specific ioctl constants with a libc specific type.
2804+
"Ioctl" => true,
2805+
28002806
_ => false,
28012807
}
28022808
});
@@ -3227,6 +3233,7 @@ fn test_linux(target: &str) {
32273233
// This function tests APIs that are incompatible to test when other APIs
32283234
// are included (e.g. because including both sets of headers clashes)
32293235
fn test_linux_like_apis(target: &str) {
3236+
let gnu = target.contains("gnu");
32303237
let musl = target.contains("musl");
32313238
let linux = target.contains("linux");
32323239
let emscripten = target.contains("emscripten");
@@ -3293,6 +3300,8 @@ fn test_linux_like_apis(target: &str) {
32933300
})
32943301
.skip_struct(|s| s != "termios2")
32953302
.type_name(move |ty, is_struct, is_union| match ty {
3303+
"Ioctl" if gnu => "unsigned long".to_string(),
3304+
"Ioctl" => "int".to_string(),
32963305
t if is_struct => format!("struct {}", t),
32973306
t if is_union => format!("union {}", t),
32983307
t => t.to_string(),

src/unix/linux_like/linux/arch/generic/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ cfg_if! {
112112
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
113113
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
114114

115-
pub const TIOCMGET: ::c_ulong = 0x5415;
116-
pub const TIOCMBIS: ::c_ulong = 0x5416;
117-
pub const TIOCMBIC: ::c_ulong = 0x5417;
118-
pub const TIOCMSET: ::c_ulong = 0x5418;
119-
pub const TCGETS2: ::c_ulong = 0x802c542a;
120-
pub const TCSETS2: ::c_ulong = 0x402c542b;
121-
pub const TCSETSW2: ::c_ulong = 0x402c542c;
122-
pub const TCSETSF2: ::c_ulong = 0x402c542d;
115+
pub const TIOCMGET: ::Ioctl = 0x5415;
116+
pub const TIOCMBIS: ::Ioctl = 0x5416;
117+
pub const TIOCMBIC: ::Ioctl = 0x5417;
118+
pub const TIOCMSET: ::Ioctl = 0x5418;
119+
pub const TCGETS2: ::Ioctl = 0x802c542a;
120+
pub const TCSETS2: ::Ioctl = 0x402c542b;
121+
pub const TCSETSW2: ::Ioctl = 0x402c542c;
122+
pub const TCSETSF2: ::Ioctl = 0x402c542d;
123123

124124
pub const TIOCM_LE: ::c_int = 0x001;
125125
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/mips/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ pub const SO_TIMESTAMPING: ::c_int = 37;
108108
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
109109
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
110110

111-
pub const TIOCMGET: ::c_ulong = 0x741d;
112-
pub const TIOCMBIS: ::c_ulong = 0x741b;
113-
pub const TIOCMBIC: ::c_ulong = 0x741c;
114-
pub const TIOCMSET: ::c_ulong = 0x741a;
115-
pub const TCGETS2: ::c_ulong = 0x4030542a;
116-
pub const TCSETS2: ::c_ulong = 0x8030542b;
117-
pub const TCSETSW2: ::c_ulong = 0x8030542c;
118-
pub const TCSETSF2: ::c_ulong = 0x8030542d;
111+
pub const TIOCMGET: ::Ioctl = 0x741d;
112+
pub const TIOCMBIS: ::Ioctl = 0x741b;
113+
pub const TIOCMBIC: ::Ioctl = 0x741c;
114+
pub const TIOCMSET: ::Ioctl = 0x741a;
115+
pub const TCGETS2: ::Ioctl = 0x4030542a;
116+
pub const TCSETS2: ::Ioctl = 0x8030542b;
117+
pub const TCSETSW2: ::Ioctl = 0x8030542c;
118+
pub const TCSETSF2: ::Ioctl = 0x8030542d;
119119

120120
pub const TIOCM_LE: ::c_int = 0x001;
121121
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/powerpc/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ pub const SO_BINDTOIFINDEX: ::c_int = 62;
9090
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
9191
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
9292

93-
pub const TIOCMGET: ::c_int = 0x5415;
94-
pub const TIOCMBIS: ::c_int = 0x5416;
95-
pub const TIOCMBIC: ::c_int = 0x5417;
96-
pub const TIOCMSET: ::c_int = 0x5418;
93+
pub const TIOCMGET: ::Ioctl = 0x5415;
94+
pub const TIOCMBIS: ::Ioctl = 0x5416;
95+
pub const TIOCMBIC: ::Ioctl = 0x5417;
96+
pub const TIOCMSET: ::Ioctl = 0x5418;
9797

9898
pub const TIOCM_LE: ::c_int = 0x001;
9999
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/sparc/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ pub const SO_TIMESTAMPING: ::c_int = 0x0023;
100100
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
101101
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
102102

103-
pub const TIOCMGET: ::c_ulong = 0x4004746a;
104-
pub const TIOCMBIS: ::c_ulong = 0x8004746c;
105-
pub const TIOCMBIC: ::c_ulong = 0x8004746b;
106-
pub const TIOCMSET: ::c_ulong = 0x8004746d;
107-
pub const TCGETS2: ::c_ulong = 0x402c540c;
108-
pub const TCSETS2: ::c_ulong = 0x802c540d;
109-
pub const TCSETSW2: ::c_ulong = 0x802c540e;
110-
pub const TCSETSF2: ::c_ulong = 0x802c540f;
103+
pub const TIOCMGET: ::Ioctl = 0x4004746a;
104+
pub const TIOCMBIS: ::Ioctl = 0x8004746c;
105+
pub const TIOCMBIC: ::Ioctl = 0x8004746b;
106+
pub const TIOCMSET: ::Ioctl = 0x8004746d;
107+
pub const TCGETS2: ::Ioctl = 0x402c540c;
108+
pub const TCSETS2: ::Ioctl = 0x802c540d;
109+
pub const TCSETSW2: ::Ioctl = 0x802c540e;
110+
pub const TCSETSF2: ::Ioctl = 0x802c540f;
111111

112112
pub const TIOCM_LE: ::c_int = 0x001;
113113
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/gnu/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ pub type __rlimit_resource_t = ::c_uint;
44
pub type Lmid_t = ::c_long;
55
pub type regoff_t = ::c_int;
66

7+
cfg_if! {
8+
if #[cfg(doc)] {
9+
// Used in `linux::arch` to define ioctl constants.
10+
pub(crate) type Ioctl = ::c_ulong;
11+
} else {
12+
#[doc(hidden)]
13+
pub type Ioctl = ::c_ulong;
14+
}
15+
}
16+
717
s! {
818
pub struct statx {
919
pub stx_mask: u32,

src/unix/linux_like/linux/musl/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ pub type rlim_t = ::c_ulonglong;
2424

2525
pub type flock64 = flock;
2626

27+
cfg_if! {
28+
if #[cfg(doc)] {
29+
// Used in `linux::arch` to define ioctl constants.
30+
pub(crate) type Ioctl = ::c_int;
31+
} else {
32+
#[doc(hidden)]
33+
pub type Ioctl = ::c_int;
34+
}
35+
}
36+
2737
impl siginfo_t {
2838
pub unsafe fn si_addr(&self) -> *mut ::c_void {
2939
#[repr(C)]

src/unix/linux_like/linux/uclibc/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ pub type regoff_t = ::c_int;
55
pub type __rlimit_resource_t = ::c_uint;
66
pub type __priority_which_t = ::c_uint;
77

8+
cfg_if! {
9+
if #[cfg(doc)] {
10+
// Used in `linux::arch` to define ioctl constants.
11+
pub(crate) type Ioctl = ::c_int;
12+
} else {
13+
#[doc(hidden)]
14+
pub type Ioctl = ::c_int;
15+
}
16+
}
17+
818
s! {
919
pub struct statvfs { // Different than GNU!
1020
pub f_bsize: ::c_ulong,

0 commit comments

Comments
 (0)