|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | //! Macros and wrapper functions for dealing with ioctls.
|
6 |
| -
|
7 |
| -use std::os::raw::c_uint; |
| 6 | +use libc; |
| 7 | +use std::os::raw::{c_int, c_uint, c_ulong, c_void}; |
| 8 | +use std::os::unix::io::AsRawFd; |
8 | 9 |
|
9 | 10 | /// Raw macro to declare a function that returns an ioctl number.
|
10 | 11 | #[macro_export]
|
@@ -77,88 +78,38 @@ pub const IOC_INOUT: c_uint = 3221225472;
|
77 | 78 | pub const IOCSIZE_MASK: c_uint = 1073676288;
|
78 | 79 | pub const IOCSIZE_SHIFT: c_uint = 16;
|
79 | 80 |
|
80 |
| -/// separate module to deal with calling ioctl's inside libc |
81 |
| -/// libc musl has as second parameter an i32 so separate code goes for that |
82 |
| -#[cfg(not(target_env = "musl"))] |
83 |
| -pub mod libc_ioctl { |
84 |
| - use libc; |
85 |
| - use std::os::raw::{c_int, c_ulong, c_void}; |
86 |
| - use std::os::unix::io::AsRawFd; |
87 |
| - |
88 |
| - /// Run an ioctl with no arguments. |
89 |
| - pub unsafe fn ioctl<F: AsRawFd>(fd: &F, request: c_ulong) -> c_int { |
90 |
| - libc::ioctl(fd.as_raw_fd(), request, 0) |
91 |
| - } |
92 |
| - |
93 |
| - /// Run an ioctl with a single value argument. |
94 |
| - pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, request: c_ulong, arg: c_ulong) -> c_int { |
95 |
| - libc::ioctl(fd.as_raw_fd(), request, arg) |
96 |
| - } |
97 |
| - |
98 |
| - /// Run an ioctl with an immutable reference. |
99 |
| - pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, request: c_ulong, arg: &T) -> c_int { |
100 |
| - libc::ioctl(fd.as_raw_fd(), request, arg as *const T as *const c_void) |
101 |
| - } |
102 |
| - |
103 |
| - /// Run an ioctl with a mutable reference. |
104 |
| - pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>( |
105 |
| - fd: &F, |
106 |
| - request: c_ulong, |
107 |
| - arg: &mut T, |
108 |
| - ) -> c_int { |
109 |
| - libc::ioctl(fd.as_raw_fd(), request, arg as *mut T as *mut c_void) |
110 |
| - } |
111 |
| - |
112 |
| - /// Run an ioctl with a raw pointer. |
113 |
| - pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, request: c_ulong, arg: *const T) -> c_int { |
114 |
| - libc::ioctl(fd.as_raw_fd(), request, arg as *const c_void) |
115 |
| - } |
116 |
| - |
117 |
| - /// Run an ioctl with a mutable raw pointer. |
118 |
| - pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>( |
119 |
| - fd: &F, |
120 |
| - request: c_ulong, |
121 |
| - arg: *mut T, |
122 |
| - ) -> c_int { |
123 |
| - libc::ioctl(fd.as_raw_fd(), request, arg as *mut c_void) |
124 |
| - } |
| 81 | +/// Run an ioctl with no arguments. |
| 82 | +pub unsafe fn ioctl<F: AsRawFd>(fd: &F, req: c_ulong) -> c_int { |
| 83 | + libc::ioctl(fd.as_raw_fd(), req as c_int, 0) |
125 | 84 | }
|
126 | 85 |
|
127 |
| -#[cfg(target_env = "musl")] |
128 |
| -pub mod libc_ioctl { |
129 |
| - use libc; |
130 |
| - use std::os::raw::{c_int, c_ulong, c_void}; |
131 |
| - use std::os::unix::io::AsRawFd; |
132 |
| - |
133 |
| - /// Run an ioctl with no arguments. |
134 |
| - pub unsafe fn ioctl<F: AsRawFd>(fd: &F, req: c_ulong) -> c_int { |
135 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, 0) |
136 |
| - } |
137 |
| - |
138 |
| - /// Run an ioctl with a single value argument. |
139 |
| - pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, req: c_ulong, arg: c_ulong) -> c_int { |
140 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, arg) |
141 |
| - } |
| 86 | +/// Run an ioctl with a single value argument. |
| 87 | +pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, req: c_ulong, arg: c_ulong) -> c_int { |
| 88 | + libc::ioctl(fd.as_raw_fd(), req as c_int, arg) |
| 89 | +} |
142 | 90 |
|
143 |
| - /// Run an ioctl with an immutable reference. |
144 |
| - pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &T) -> c_int { |
145 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, arg as *const T as *const c_void) |
146 |
| - } |
| 91 | +/// Run an ioctl with an immutable reference. |
| 92 | +pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &T) -> c_int { |
| 93 | + libc::ioctl( |
| 94 | + fd.as_raw_fd(), |
| 95 | + req as c_int, |
| 96 | + arg as *const T as *const c_void, |
| 97 | + ) |
| 98 | +} |
147 | 99 |
|
148 |
| - /// Run an ioctl with a mutable reference. |
149 |
| - pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &mut T) -> c_int { |
150 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, arg as *mut T as *mut c_void) |
151 |
| - } |
| 100 | +/// Run an ioctl with a mutable reference. |
| 101 | +pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &mut T) -> c_int { |
| 102 | + libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *mut T as *mut c_void) |
| 103 | +} |
152 | 104 |
|
153 |
| - /// Run an ioctl with a raw pointer. |
154 |
| - pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *const T) -> c_int { |
155 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, arg as *const c_void) |
156 |
| - } |
| 105 | +/// Run an ioctl with a raw pointer. |
| 106 | +pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *const T) -> c_int { |
| 107 | + libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *const c_void) |
| 108 | +} |
157 | 109 |
|
158 |
| - /// Run an ioctl with a mutable raw pointer. |
159 |
| - pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *mut T) -> c_int { |
160 |
| - libc::ioctl(fd.as_raw_fd(), req as i32, arg as *mut c_void) |
161 |
| - } |
| 110 | +/// Run an ioctl with a mutable raw pointer. |
| 111 | +pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *mut T) -> c_int { |
| 112 | + libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *mut c_void) |
162 | 113 | }
|
163 | 114 |
|
164 | 115 | #[cfg(test)]
|
|
0 commit comments