11 getpts(int fd[], char *slave)
16 fd[1] = open("/dev/ptmx", ORDWR);
17 f = signal(SIGCLD, SIG_DFL);
20 if(r < 0 || unlockpt(fd[1]) < 0)
24 strcpy(slave, ptsname(fd[1]));
26 fd[0] = open(slave, ORDWR);
28 sysfatal("open %s: %r\n", slave);
30 /* set up the right streams modules for a tty */
31 ioctl(fd[0], I_PUSH, "ptem"); /* push ptem */
32 ioctl(fd[0], I_PUSH, "ldterm"); /* push ldterm */
38 childpty(int fd[], char *slave)
44 sfd = open(slave, ORDWR);
46 sysfatal("open %s: %r\n", slave);
53 updatewinsize(int row, int col, int dx, int dy)
61 if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
62 if(ioctl(rcfd, TIOCSWINSZ, &ws) < 0)
63 fprint(2, "ioctl TIOCSWINSZ: %r\n");
67 static struct termios ttmode;
72 if(tcgetattr(fd, &ttmode) < 0)
73 fprint(2, "tcgetattr: %r\n");
74 if(debug) fprint(2, "israw %c%c\n",
75 ttmode.c_lflag&ICANON ? 'c' : '-',
76 ttmode.c_lflag&ECHO ? 'e' : '-');
77 return (ttmode.c_lflag&ICANON && ttmode.c_lflag&ECHO);
81 setecho(int fd, int newe)
85 if(tcgetattr(fd, &ttmode) < 0)
86 fprint(2, "tcgetattr: %r\n");
87 old = (ttmode.c_lflag&ECHO)==ECHO;
90 ttmode.c_lflag |= ECHO;
92 ttmode.c_lflag &= ~ECHO;
93 if(tcsetattr(fd, TCSANOW, &ttmode) < 0)
94 fprint(2, "tcsetattr: %r\n");
102 if(tcgetattr(fd, &ttmode) < 0)
104 return ttmode.c_cc[VINTR];