plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

SunOS.c (1529B)


      1 #include <u.h>
      2 #include <termios.h>
      3 #include <stropts.h>
      4 #include <signal.h>
      5 #include <libc.h>
      6 #include "term.h"
      7 
      8 #define debug 0
      9 
     10 int
     11 getpts(int fd[], char *slave)
     12 {
     13 	void (*f)(int);
     14 	int r;
     15 
     16 	fd[1] = open("/dev/ptmx", ORDWR);
     17 	f = signal(SIGCLD, SIG_DFL);
     18 	r = grantpt(fd[1]);
     19 	signal(SIGCLD, f);
     20 	if(r < 0 || unlockpt(fd[1]) < 0)
     21 		return -1;
     22 	fchmod(fd[1], 0622);
     23 
     24 	strcpy(slave, ptsname(fd[1]));
     25 
     26 	fd[0] = open(slave, ORDWR);
     27 	if(fd[0] < 0)
     28 		sysfatal("open %s: %r\n", slave);
     29 
     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 */
     33 
     34 	return 0;
     35 }
     36 
     37 int
     38 childpty(int fd[], char *slave)
     39 {
     40 	int sfd;
     41 
     42 	close(fd[1]);
     43 	setsid();
     44 	sfd = open(slave, ORDWR);
     45 	if(sfd < 0)
     46 		sysfatal("open %s: %r\n", slave);
     47 	return sfd;
     48 }
     49 
     50 struct winsize ows;
     51 
     52 void
     53 updatewinsize(int row, int col, int dx, int dy)
     54 {
     55 	struct winsize ws;
     56 
     57 	ws.ws_row = row;
     58 	ws.ws_col = col;
     59 	ws.ws_xpixel = dx;
     60 	ws.ws_ypixel = 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");
     64 	ows = ws;
     65 }
     66 
     67 static struct termios ttmode;
     68 
     69 int
     70 isecho(int fd)
     71 {
     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);
     78 }
     79 
     80 int
     81 getintr(int fd)
     82 {
     83 	if(tcgetattr(fd, &ttmode) < 0)
     84 		return 0x7F;
     85 	return ttmode.c_cc[VINTR];
     86 }