|
0 |
Author: Dorota Czaplejewicz
|
|
1 |
Forwarded: https://github.com/dcuddeback/ioctl-rs/pull/6
|
|
2 |
Description: Use a dedicated type for TIOCM requests
|
|
3 |
---
|
|
4 |
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
|
|
5 |
--- a/src/lib.rs
|
|
6 |
+++ b/src/lib.rs
|
|
7 |
@@ -41,8 +41,8 @@ pub fn tiocnxcl(fd: RawFd) -> io::Result
|
|
8 |
}
|
|
9 |
|
|
10 |
/// Get the status of modem bits.
|
|
11 |
-pub fn tiocmget(fd: RawFd) -> io::Result<c_int> {
|
|
12 |
- let mut bits: c_int = unsafe { mem::uninitialized() };
|
|
13 |
+pub fn tiocmget(fd: RawFd) -> io::Result<BitsInt> {
|
|
14 |
+ let mut bits: BitsInt = unsafe { mem::uninitialized() };
|
|
15 |
|
|
16 |
match unsafe { ioctl(fd, TIOCMGET, &mut bits) } {
|
|
17 |
0 => Ok(bits),
|
|
18 |
@@ -51,7 +51,7 @@ pub fn tiocmget(fd: RawFd) -> io::Result
|
|
19 |
}
|
|
20 |
|
|
21 |
/// Set the status of modem bits.
|
|
22 |
-pub fn tiocmset(fd: RawFd, bits: c_int) -> io::Result<()> {
|
|
23 |
+pub fn tiocmset(fd: RawFd, bits: BitsInt) -> io::Result<()> {
|
|
24 |
match unsafe { ioctl(fd, TIOCMSET, &bits) } {
|
|
25 |
0 => Ok(()),
|
|
26 |
_ => Err(io::Error::last_os_error())
|
|
27 |
@@ -59,7 +59,7 @@ pub fn tiocmset(fd: RawFd, bits: c_int)
|
|
28 |
}
|
|
29 |
|
|
30 |
/// Set the indicated modem bits.
|
|
31 |
-pub fn tiocmbis(fd: RawFd, bits: c_int) -> io::Result<()> {
|
|
32 |
+pub fn tiocmbis(fd: RawFd, bits: BitsInt) -> io::Result<()> {
|
|
33 |
match unsafe { ioctl(fd, TIOCMBIS, &bits) } {
|
|
34 |
0 => Ok(()),
|
|
35 |
_ => Err(io::Error::last_os_error())
|
|
36 |
@@ -67,9 +67,26 @@ pub fn tiocmbis(fd: RawFd, bits: c_int)
|
|
37 |
}
|
|
38 |
|
|
39 |
/// Clear the indicated modem bits.
|
|
40 |
-pub fn tiocmbic(fd: RawFd, bits: c_int) -> io::Result<()> {
|
|
41 |
+pub fn tiocmbic(fd: RawFd, bits: BitsInt) -> io::Result<()> {
|
|
42 |
match unsafe { ioctl(fd, TIOCMBIC, &bits) } {
|
|
43 |
0 => Ok(()),
|
|
44 |
_ => Err(io::Error::last_os_error())
|
|
45 |
}
|
|
46 |
}
|
|
47 |
+
|
|
48 |
+#[cfg(test)]
|
|
49 |
+mod tests {
|
|
50 |
+ use super::*;
|
|
51 |
+ ///
|
|
52 |
+ /// Will fail to compile if types don't match.
|
|
53 |
+ #[allow(dead_code)]
|
|
54 |
+ fn compile_bits() {
|
|
55 |
+ tiocmbic(0, TIOCM_RTS).unwrap();
|
|
56 |
+ }
|
|
57 |
+
|
|
58 |
+ #[allow(dead_code)]
|
|
59 |
+ fn compile_get_bits() {
|
|
60 |
+ let bits = tiocmget(0).unwrap();
|
|
61 |
+ tiocmset(0, bits).unwrap();
|
|
62 |
+ }
|
|
63 |
+}
|
|
64 |
--- a/src/os/dragonfly.rs
|
|
65 |
+++ b/src/os/dragonfly.rs
|
|
66 |
@@ -67,6 +67,8 @@ pub const TIOCM_RNG: c_int = 0x00000080;
|
|
67 |
pub const TIOCM_RI: c_int = 0x00000080;
|
|
68 |
pub const TIOCM_DSR: c_int = 0x00000100;
|
|
69 |
|
|
70 |
+pub type BitsInt = c_int;
|
|
71 |
+
|
|
72 |
extern "C" {
|
|
73 |
pub fn ioctl(fildes: c_int, request: c_ulong, ...) -> c_int;
|
|
74 |
}
|
|
75 |
--- a/src/os/freebsd.rs
|
|
76 |
+++ b/src/os/freebsd.rs
|
|
77 |
@@ -67,6 +67,8 @@ pub const TIOCM_RNG: c_int = 0x00000080;
|
|
78 |
pub const TIOCM_RI: c_int = 0x00000080;
|
|
79 |
pub const TIOCM_DSR: c_int = 0x00000100;
|
|
80 |
|
|
81 |
+pub type BitsInt = c_int;
|
|
82 |
+
|
|
83 |
extern "C" {
|
|
84 |
pub fn ioctl(fildes: c_int, request: c_ulong, ...) -> c_int;
|
|
85 |
}
|
|
86 |
--- a/src/os/linux.rs
|
|
87 |
+++ b/src/os/linux.rs
|
|
88 |
@@ -115,6 +115,8 @@ pub const TIOCM_RNG: c_uint = 0x00000080
|
|
89 |
pub const TIOCM_RI: c_uint = 0x00000080;
|
|
90 |
pub const TIOCM_DSR: c_uint = 0x00000100;
|
|
91 |
|
|
92 |
+pub type BitsInt = c_uint;
|
|
93 |
+
|
|
94 |
extern "C" {
|
|
95 |
pub fn ioctl(fd: c_int, request: c_uint, ...) -> c_int;
|
|
96 |
}
|
|
97 |
--- a/src/os/macos.rs
|
|
98 |
+++ b/src/os/macos.rs
|
|
99 |
@@ -76,6 +76,8 @@ pub const TIOCM_RNG: c_int = 0x00000080;
|
|
100 |
pub const TIOCM_RI: c_int = 0x00000080;
|
|
101 |
pub const TIOCM_DSR: c_int = 0x00000100;
|
|
102 |
|
|
103 |
+pub type BitsInt = c_int;
|
|
104 |
+
|
|
105 |
extern "C" {
|
|
106 |
pub fn ioctl(fildes: c_int, request: c_ulong, ...) -> c_int;
|
|
107 |
}
|
|
108 |
--- a/src/os/openbsd.rs
|
|
109 |
+++ b/src/os/openbsd.rs
|
|
110 |
@@ -67,6 +67,8 @@ pub const TIOCM_RNG: c_int = 0x00000080;
|
|
111 |
pub const TIOCM_RI: c_int = 0x00000080;
|
|
112 |
pub const TIOCM_DSR: c_int = 0x00000100;
|
|
113 |
|
|
114 |
+pub type BitsInt = c_int;
|
|
115 |
+
|
|
116 |
extern "C" {
|
|
117 |
pub fn ioctl(fildes: c_int, request: c_ulong, ...) -> c_int;
|
|
118 |
}
|