1 be22ae2d 2004-03-26 devnull #include <u.h>
2 8ad51794 2004-03-25 devnull #include <termios.h>
3 4dcd9af2 2004-04-15 devnull #include <stropts.h>
4 be22ae2d 2004-03-26 devnull #include <libc.h>
5 be22ae2d 2004-03-26 devnull #include "term.h"
7 a2705f20 2004-04-16 devnull #define debug 0
10 e642beb5 2003-11-25 devnull getpts(int fd[], char *slave)
12 e642beb5 2003-11-25 devnull fd[1] = open("/dev/ptmx", ORDWR);
13 e642beb5 2003-11-25 devnull if ((grantpt(fd[1]) < 0) || (unlockpt(fd[1]) < 0))
14 e642beb5 2003-11-25 devnull return -1;
15 e642beb5 2003-11-25 devnull fchmod(fd[1], 0622);
17 e642beb5 2003-11-25 devnull strcpy(slave, ptsname(fd[1]));
19 4dcd9af2 2004-04-15 devnull fd[0] = open(slave, ORDWR);
20 4dcd9af2 2004-04-15 devnull if(fd[0] < 0)
21 4dcd9af2 2004-04-15 devnull sysfatal("open %s: %r\n", slave);
23 4dcd9af2 2004-04-15 devnull /* set up the right streams modules for a tty */
24 4dcd9af2 2004-04-15 devnull ioctl(fd[0], I_PUSH, "ptem"); /* push ptem */
25 4dcd9af2 2004-04-15 devnull ioctl(fd[0], I_PUSH, "ldterm"); /* push ldterm */
27 e642beb5 2003-11-25 devnull return 0;
31 be22ae2d 2004-03-26 devnull childpty(int fd[], char *slave)
35 be22ae2d 2004-03-26 devnull close(fd[1]);
36 be22ae2d 2004-03-26 devnull setsid();
37 be22ae2d 2004-03-26 devnull sfd = open(slave, ORDWR);
38 be22ae2d 2004-03-26 devnull if(sfd < 0)
39 be22ae2d 2004-03-26 devnull sysfatal("open %s: %r\n", slave);
40 be22ae2d 2004-03-26 devnull return sfd;
43 8ad51794 2004-03-25 devnull struct winsize ows;
46 8ad51794 2004-03-25 devnull updatewinsize(int row, int col, int dx, int dy)
48 8ad51794 2004-03-25 devnull struct winsize ws;
50 8ad51794 2004-03-25 devnull ws.ws_row = row;
51 8ad51794 2004-03-25 devnull ws.ws_col = col;
52 8ad51794 2004-03-25 devnull ws.ws_xpixel = dx;
53 8ad51794 2004-03-25 devnull ws.ws_ypixel = dy;
54 8ad51794 2004-03-25 devnull if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
55 be22ae2d 2004-03-26 devnull if(ioctl(rcfd, TIOCSWINSZ, &ws) < 0)
56 4dcd9af2 2004-04-15 devnull fprint(2, "ioctl TIOCSWINSZ: %r\n");
57 8ad51794 2004-03-25 devnull ows = ws;
60 4dcd9af2 2004-04-15 devnull static struct termios ttmode;
63 a0f1e21f 2004-04-20 devnull isecho(int fd)
65 a2705f20 2004-04-16 devnull if(tcgetattr(fd, &ttmode) < 0)
66 a2705f20 2004-04-16 devnull fprint(2, "tcgetattr: %r\n");
67 a2705f20 2004-04-16 devnull if(debug) fprint(2, "israw %c%c\n",
68 a2705f20 2004-04-16 devnull ttmode.c_lflag&ICANON ? 'c' : '-',
69 a2705f20 2004-04-16 devnull ttmode.c_lflag&ECHO ? 'e' : '-');
70 a0f1e21f 2004-04-20 devnull return (ttmode.c_lflag&(ICANON|ECHO));
74 a2705f20 2004-04-16 devnull setecho(int fd, int newe)
78 a2705f20 2004-04-16 devnull if(tcgetattr(fd, &ttmode) < 0)
79 a2705f20 2004-04-16 devnull fprint(2, "tcgetattr: %r\n");
80 a2705f20 2004-04-16 devnull old = (ttmode.c_lflag&ECHO)==ECHO;
81 a2705f20 2004-04-16 devnull if(old != newe){
83 a2705f20 2004-04-16 devnull ttmode.c_lflag |= ECHO;
85 a2705f20 2004-04-16 devnull ttmode.c_lflag &= ~ECHO;
86 a2705f20 2004-04-16 devnull if(tcsetattr(fd, TCSANOW, &ttmode) < 0)
87 a2705f20 2004-04-16 devnull fprint(2, "tcsetattr: %r\n");
89 a2705f20 2004-04-16 devnull return old;