8 #include <sys/termios.h>
19 "abcdefghijklmnopqrstuvwxyz"
20 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
24 "abcdefghijklmnopqrstuvwxyz"
25 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
28 getpts(int fd[], char *slave)
31 char pty[] = "/dev/ptyXX";
37 if((fd[1] = open(pty, ORDWR)) < 0){
44 if((fd[0] = open(slave, ORDWR)) >= 0)
54 childpty(int fd[], char *slave)
58 close(fd[1]); /* drop master */
60 sfd = open(slave, ORDWR);
62 sysfatal("child open %s: %r\n", slave);
63 if(ioctl(sfd, TIOCSCTTY, 0) < 0)
64 fprint(2, "ioctl TIOCSCTTY: %r\n");
71 updatewinsize(int row, int col, int dx, int dy)
79 if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
80 if(ioctl(rcfd, TIOCSWINSZ, &ws) < 0)
81 fprint(2, "ioctl: %r\n");
85 static struct termios ttmode;
90 if(tcgetattr(fd, &ttmode) < 0)
91 fprint(2, "tcgetattr: %r\n");
92 if(debug) fprint(2, "israw %c%c\n",
93 ttmode.c_lflag&ICANON ? 'c' : '-',
94 ttmode.c_lflag&ECHO ? 'e' : '-');
95 return ttmode.c_lflag&ECHO;
99 setecho(int fd, int newe)
103 if(tcgetattr(fd, &ttmode) < 0)
104 fprint(2, "tcgetattr: %r\n");
105 old = ttmode.c_lflag & ECHO;
107 ttmode.c_lflag &= ~ECHO;
108 ttmode.c_lflag |= newe;
110 * I tried using TCSADRAIN here, but that causes
111 * hangs if there is any output waiting for us.
112 * I guess TCSADRAIN is intended for use by our
113 * clients, not by us.
115 if(tcsetattr(fd, 0, &ttmode) < 0)
116 fprint(2, "tcsetattr: %r\n");