In article <1993Jul31.101301.11068@lugb.latrobe.edu.au>
ecsgrt@luxor.latrobe.edu.au (I, Geoffrey Tobin) claimed:
>On a Sparc 10 running Solaris 2.1, I'm maintaining C code (written
>by another person and/or program) ...
Then I asserted that ICANON did not behave as I expected from
"man termio".
This was doubly false. Firstly, ICANON, correctly used, behaves
exactly as expected. Secondly, the faulty code was mine. I tried to
use TIOCGETP and TIOCSETN with a "struct termio" variable!
Guy Harris <guy@auspex.com> instructed me that:
(1) TIOCGETP and TIOCSETN belong with "struct sgtty".
(2) "struct termio" goes with TCGETA, TCSETA, TCSETAW and TCSETAF.
Dave Curry <davy@ecn.purdue.edu> also pointed this out to me, and
sent me some correct code, which I append for those interested.
Bill Wisner <wisner@well.sf.ca.us> suggested I use the preferred
interface, tcgetattr() and tcsetattr(), not ioctl().
Geoffrey Tobin
---------------------------------%<-----------------------------------
The attached program works just fine; feel free to use any part of it.
--Dave
/* ----------- cut here ----------- */
#include <termio.h>
main()
{
int n;
char buf[1024];
struct termio ts;
printf("Entering single-character mode. Type RETURN to exit.\n");
singlecharon();
for (;;) {
printf("\nEnter a character: ");
if ((n = read(0, buf, sizeof(buf))) < 0) {
singlecharoff();
exit(0);
}
buf[n] = '\0';
printf("\nRead %d chars, you typed \"%s\"\n", n, buf);
if (buf[0] == '\n') {
singlecharoff();
exit(0);
}
}
}
singlecharon()
{
struct termio ts;
ioctl(0, TCGETA, &ts);
ts.c_lflag &= ~ICANON;
ts.c_cc[VTIME] = 0;
ts.c_cc[VMIN] = 1;
ioctl(0, TCSETA, &ts);
}
singlecharoff()
{
struct termio ts;
ioctl(0, TCGETA, &ts);
ts.c_lflag |= ICANON;
ioctl(0, TCSETA, &ts);
}
---------------------------------%<-----------------------------------
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:06 CDT