Skip to content

Commit f1ad2f5

Browse files
authored
Merge pull request #1717 from jclulow/illumos-cfmakeraw
fix cfmakeraw() for illumos and Solaris
2 parents 1d9e5fb + 5b6a333 commit f1ad2f5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/unix/solarish/compat.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use unix::solarish::*;
55

66
pub unsafe fn cfmakeraw(termios: *mut ::termios) {
7-
let mut t = *termios as ::termios;
8-
t.c_iflag &= !(IMAXBEL
7+
(*termios).c_iflag &= !(IMAXBEL
98
| IGNBRK
109
| BRKINT
1110
| PARMRK
@@ -14,10 +13,26 @@ pub unsafe fn cfmakeraw(termios: *mut ::termios) {
1413
| IGNCR
1514
| ICRNL
1615
| IXON);
17-
t.c_oflag &= !OPOST;
18-
t.c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
19-
t.c_cflag &= !(CSIZE | PARENB);
20-
t.c_cflag |= CS8;
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;
2136
}
2237

2338
pub unsafe fn cfsetspeed(

0 commit comments

Comments
 (0)