removed support for -r, -h, and rmail
[unix-history] / usr / src / usr.bin / window / wwpty.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
60de5df9
EW
11 */
12
46e9ea25
KB
13#ifndef lint
14static char sccsid[] = "@(#)wwpty.c 3.14 (Berkeley) %G%";
15#endif /* not lint */
16
c9b68ede
EW
17#include "ww.h"
18
19wwgetpty(w)
c2acc030 20register struct ww *w;
c9b68ede 21{
01135bd2 22 register char c, *p;
c2acc030 23 int tty;
8fa6d94c 24 int on = 1;
c2acc030
EW
25#define PTY "/dev/XtyXX"
26#define _PT 5
27#define _PQRS 8
28#define _0_9 9
c9b68ede 29
c2acc030 30 (void) strcpy(w->ww_ttyname, PTY);
01135bd2 31 for (c = 'p'; c <= 'u'; c++) {
c2acc030
EW
32 w->ww_ttyname[_PT] = 'p';
33 w->ww_ttyname[_PQRS] = c;
34 w->ww_ttyname[_0_9] = '0';
35 if (access(w->ww_ttyname, 0) < 0)
c9b68ede 36 break;
01135bd2 37 for (p = "0123456789abcdef"; *p; p++) {
c2acc030 38 w->ww_ttyname[_PT] = 'p';
01135bd2 39 w->ww_ttyname[_0_9] = *p;
c2acc030
EW
40 if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0)
41 continue;
42 w->ww_ttyname[_PT] = 't';
43 if ((tty = open(w->ww_ttyname, 2)) < 0) {
44 (void) close(w->ww_pty);
45 continue;
c9b68ede 46 }
c2acc030 47 (void) close(tty);
20029082 48 if (ioctl(w->ww_pty, TIOCPKT, (char *)&on) < 0) {
8fa6d94c
EW
49 (void) close(w->ww_pty);
50 continue;
51 }
c2acc030 52 return 0;
c9b68ede
EW
53 }
54 }
eec72f58 55 w->ww_pty = -1;
03e75950 56 wwerrno = WWE_NOPTY;
c9b68ede 57 return -1;
c9b68ede 58}