1 // Common functions that are unfortunately missing on illumos and
2 // Solaris, but often needed by other crates.
3 
4 use unix::solarish::*;
5 
cfmakeraw(termios: *mut ::termios)6 pub unsafe fn cfmakeraw(termios: *mut ::termios) {
7     (*termios).c_iflag &= !(IMAXBEL
8         | IGNBRK
9         | BRKINT
10         | PARMRK
11         | ISTRIP
12         | INLCR
13         | IGNCR
14         | ICRNL
15         | IXON);
16     (*termios).c_oflag &= !OPOST;
17     (*termios).c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
18     (*termios).c_cflag &= !(CSIZE | PARENB);
19     (*termios).c_cflag |= CS8;
20 
21     // By default, most software expects a pending read to block until at
22     // least one byte becomes available.  As per termio(7I), this requires
23     // setting the MIN and TIME parameters appropriately.
24     //
25     // As a somewhat unfortunate artefact of history, the MIN and TIME slots
26     // in the control character array overlap with the EOF and EOL slots used
27     // for canonical mode processing.  Because the EOF character needs to be
28     // the ASCII EOT value (aka Control-D), it has the byte value 4.  When
29     // switching to raw mode, this is interpreted as a MIN value of 4; i.e.,
30     // reads will block until at least four bytes have been input.
31     //
32     // Other platforms with a distinct MIN slot like Linux and FreeBSD appear
33     // to default to a MIN value of 1, so we'll force that value here:
34     (*termios).c_cc[VMIN] = 1;
35     (*termios).c_cc[VTIME] = 0;
36 }
37 
cfsetspeed( termios: *mut ::termios, speed: ::speed_t, ) -> ::c_int38 pub unsafe fn cfsetspeed(
39     termios: *mut ::termios,
40     speed: ::speed_t,
41 ) -> ::c_int {
42     // Neither of these functions on illumos or Solaris actually ever
43     // return an error
44     ::cfsetispeed(termios, speed);
45     ::cfsetospeed(termios, speed);
46     0
47 }
48