@@ -145,25 +145,71 @@ pub(crate) fn set_termios(fd: RawFd, termios: &Termios) -> Result<()> {
145
145
crate :: posix:: ioctl:: tcsets2 ( fd, termios)
146
146
}
147
147
148
- pub ( crate ) fn set_parity ( termios : & mut Termios , parity : Parity ) {
148
+ // The Result return will seem pointless on platforms that support all parity variants, but we need
149
+ // it for the others.
150
+ #[ allow( clippy:: unnecessary_wraps) ]
151
+ pub ( crate ) fn set_parity ( termios : & mut Termios , parity : Parity ) -> Result < ( ) > {
149
152
match parity {
150
153
Parity :: None => {
151
154
termios. c_cflag &= !( libc:: PARENB | libc:: PARODD ) ;
152
155
termios. c_iflag &= !libc:: INPCK ;
153
156
termios. c_iflag |= libc:: IGNPAR ;
157
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
158
+ {
159
+ termios. c_iflag &= !libc:: CMSPAR ;
160
+ }
154
161
}
155
162
Parity :: Odd => {
156
163
termios. c_cflag |= libc:: PARENB | libc:: PARODD ;
157
164
termios. c_iflag |= libc:: INPCK ;
158
165
termios. c_iflag &= !libc:: IGNPAR ;
166
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
167
+ {
168
+ termios. c_iflag &= !libc:: CMSPAR ;
169
+ }
159
170
}
160
171
Parity :: Even => {
161
172
termios. c_cflag &= !libc:: PARODD ;
162
173
termios. c_cflag |= libc:: PARENB ;
163
174
termios. c_iflag |= libc:: INPCK ;
164
175
termios. c_iflag &= !libc:: IGNPAR ;
176
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
177
+ {
178
+ termios. c_iflag &= !libc:: CMSPAR ;
179
+ }
180
+ }
181
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
182
+ Parity :: Mark => {
183
+ termios. c_cflag |= libc:: PARODD ;
184
+ termios. c_cflag |= libc:: PARENB ;
185
+ termios. c_iflag |= libc:: INPCK ;
186
+ termios. c_iflag &= !libc:: IGNPAR ;
187
+ termios. c_iflag |= libc:: CMSPAR ;
188
+ }
189
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
190
+ Parity :: Space => {
191
+ termios. c_cflag &= !libc:: PARODD ;
192
+ termios. c_cflag |= libc:: PARENB ;
193
+ termios. c_iflag |= libc:: INPCK ;
194
+ termios. c_iflag &= !libc:: IGNPAR ;
195
+ termios. c_iflag |= libc:: CMSPAR ;
196
+ }
197
+ #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
198
+ Parity :: Mark => {
199
+ return Err ( crate :: Error :: new (
200
+ crate :: ErrorKind :: InvalidInput ,
201
+ "Mark parity not supported on this platform" ,
202
+ ) ) ;
203
+ }
204
+ #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
205
+ Parity :: Space => {
206
+ return Err ( crate :: Error :: new (
207
+ crate :: ErrorKind :: InvalidInput ,
208
+ "Space parity not supported on this platform" ,
209
+ ) ) ;
165
210
}
166
211
} ;
212
+ Ok ( ( ) )
167
213
}
168
214
169
215
pub ( crate ) fn set_flow_control ( termios : & mut Termios , flow_control : FlowControl ) {
0 commit comments