Date: Wed, 17 Sep 2025 10:25:08 -0400
From: Greg Wooledge <[email protected]>
Message-ID: <[email protected]>
| I can't tell what those ioctl() calls are doing. Why call TCGETS three
| times in a row?
That's a good question ... and the TCGETS after the (successful) TCSETSW,
which is, I presume, just checking that it really did what it said it had
done ... some optimisation could be done there I think -- but it isn't always
as trivial as it seems like it might be, as other things can change the
terminal modes as well, and readline and the shell I assume are each kind
of doing their own thing.
| And sadly, the special characters (c_cc) being passed
| on the TCSETSW call are not shown by strace.
I doubt it matters, what does, is that ICANON is being turned off by
that call (the first one, and restored by the second). That surprises
me for just -d processing, switching to (what used to be called) cbreak
mode (not quite raw mode) for that, when setting the eol char (VEOL)
causes the specified char to act just like a newline, which is all that
-d processing requires. Things get messier to handle -n, but that's not
in use here. ICANON off causes the byte at a time returns (more acurately,
whatever is available when the read happens - but few humans can type faster
than a computer can return each byte and request the next, so there is
rarely an opportunity for more than 1 to become available) - it also turns
off all tty driver editing (but not signal generation).
kre