use openpty() instead of rolling a custom function (which didn't support

the full range of ptys anyways)
This commit is contained in:
Bill Fumerola 2001-09-28 22:46:13 +00:00
parent 4f49d5f058
commit 5b3f2c13a2
2 changed files with 18 additions and 30 deletions

View File

@ -16,6 +16,6 @@ SRCS= char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \
wwterminfo.c wwtty.c wwunframe.c wwupdate.c wwwrite.c xx.c xxflush.c \
compress.c
DPADD= ${LIBTERMCAP}
LDADD= -ltermcap
LDADD= -ltermcap -lutil
.include <bsd.prog.mk>

View File

@ -42,6 +42,7 @@ static char rcsid[] =
#include "ww.h"
#include <fcntl.h>
#include <stdlib.h>
#if !defined(OLD_TTY) && !defined(TIOCPKT)
#include <sys/ioctl.h>
#endif
@ -49,41 +50,28 @@ static char rcsid[] =
wwgetpty(w)
register struct ww *w;
{
register char c, *p;
int tty;
int on = 1;
char *ttyname;
int master, slave, on;
#define PTY "/dev/XtyXX"
#define _PT 5
#define _PQRS 8
#define _0_9 9
(void) strcpy(w->ww_ttyname, PTY);
for (c = 'p'; c <= 'u'; c++) {
w->ww_ttyname[_PT] = 'p';
w->ww_ttyname[_PQRS] = c;
w->ww_ttyname[_0_9] = '0';
if (access(w->ww_ttyname, 0) < 0)
break;
for (p = "0123456789abcdefghijklmnopqrstuv"; *p; p++) {
w->ww_ttyname[_PT] = 'p';
w->ww_ttyname[_0_9] = *p;
if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0)
continue;
w->ww_ttyname[_PT] = 't';
if ((tty = open(w->ww_ttyname, 2)) < 0) {
(void) close(w->ww_pty);
continue;
}
(void) close(tty);
if (ioctl(w->ww_pty, TIOCPKT, (char *)&on) < 0) {
(void) close(w->ww_pty);
continue;
}
on = 1;
w->ww_pty = -1;
ttyname = malloc(strlen(PTY) + 1);
if (openpty(&master, &slave, ttyname, NULL, NULL) == 0) {
w->ww_pty = master;
(void) strcpy(w->ww_ttyname, ttyname);
if (ioctl(w->ww_pty, TIOCPKT, (char *)&on) < 0) {
(void) close(w->ww_pty);
wwerrno = WWE_SYS;
} else {
(void) fcntl(w->ww_pty, F_SETFD, 1);
free(ttyname);
return 0;
}
}
w->ww_pty = -1;
free(ttyname);
wwerrno = WWE_NOPTY;
return -1;
}