aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Fumerola <billf@FreeBSD.org>2001-09-28 22:46:13 +0000
committerBill Fumerola <billf@FreeBSD.org>2001-09-28 22:46:13 +0000
commit5b3f2c13a2c514d5c5f75c164c112de7ce49389d (patch)
tree492ceef0609ca6057f7c1615753a2733de4660e0
parent4f49d5f05898927ecaa05517af028890f50181a1 (diff)
downloadsrc-5b3f2c13a2c514d5c5f75c164c112de7ce49389d.tar.gz
src-5b3f2c13a2c514d5c5f75c164c112de7ce49389d.zip
use openpty() instead of rolling a custom function (which didn't support
the full range of ptys anyways)
Notes
Notes: svn path=/head/; revision=84096
-rw-r--r--usr.bin/window/Makefile2
-rw-r--r--usr.bin/window/wwpty.c46
2 files changed, 18 insertions, 30 deletions
diff --git a/usr.bin/window/Makefile b/usr.bin/window/Makefile
index 8615265d6789..4641609f2fe4 100644
--- a/usr.bin/window/Makefile
+++ b/usr.bin/window/Makefile
@@ -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>
diff --git a/usr.bin/window/wwpty.c b/usr.bin/window/wwpty.c
index 9f84ab3351ec..d26280baf4c0 100644
--- a/usr.bin/window/wwpty.c
+++ b/usr.bin/window/wwpty.c
@@ -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;
}