@@ -145,25 +145,71 @@ pub(crate) fn set_termios(fd: RawFd, termios: &Termios) -> Result<()> {
145145 crate :: posix:: ioctl:: tcsets2 ( fd, termios)
146146}
147147
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 < ( ) > {
149152 match parity {
150153 Parity :: None => {
151154 termios. c_cflag &= !( libc:: PARENB | libc:: PARODD ) ;
152155 termios. c_iflag &= !libc:: INPCK ;
153156 termios. c_iflag |= libc:: IGNPAR ;
157+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
158+ {
159+ termios. c_iflag &= !libc:: CMSPAR ;
160+ }
154161 }
155162 Parity :: Odd => {
156163 termios. c_cflag |= libc:: PARENB | libc:: PARODD ;
157164 termios. c_iflag |= libc:: INPCK ;
158165 termios. c_iflag &= !libc:: IGNPAR ;
166+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
167+ {
168+ termios. c_iflag &= !libc:: CMSPAR ;
169+ }
159170 }
160171 Parity :: Even => {
161172 termios. c_cflag &= !libc:: PARODD ;
162173 termios. c_cflag |= libc:: PARENB ;
163174 termios. c_iflag |= libc:: INPCK ;
164175 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+ ) ) ;
165210 }
166211 } ;
212+ Ok ( ( ) )
167213}
168214
169215pub ( crate ) fn set_flow_control ( termios : & mut Termios , flow_control : FlowControl ) {
0 commit comments