summaryrefslogtreecommitdiffstats
path: root/usr.bin/window
diff options
context:
space:
mode:
authorbillf <billf@FreeBSD.org>2001-09-28 22:46:13 +0000
committerbillf <billf@FreeBSD.org>2001-09-28 22:46:13 +0000
commit5f0513c0ec8c5c90bc0e3c5a9ccb5dfc0af4d7ca (patch)
tree492ceef0609ca6057f7c1615753a2733de4660e0 /usr.bin/window
parent218bb1b355d9b51419d9bc59e3d116098225e166 (diff)
downloadFreeBSD-src-5f0513c0ec8c5c90bc0e3c5a9ccb5dfc0af4d7ca.zip
FreeBSD-src-5f0513c0ec8c5c90bc0e3c5a9ccb5dfc0af4d7ca.tar.gz
use openpty() instead of rolling a custom function (which didn't support
the full range of ptys anyways)
Diffstat (limited to 'usr.bin/window')
-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 8615265..4641609 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 9f84ab3..d26280b 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;
}
OpenPOWER on IntegriCloud