Commit | Line | Data |
---|---|---|
c9b68ede | 1 | #ifndef lint |
60de5df9 | 2 | static char sccsid[] = "@(#)wwpty.c 3.11 %G%"; |
c9b68ede EW |
3 | #endif |
4 | ||
60de5df9 EW |
5 | /* |
6 | * Copyright (c) 1983 Regents of the University of California, | |
7 | * All rights reserved. Redistribution permitted subject to | |
8 | * the terms of the Berkeley Software License Agreement. | |
9 | */ | |
10 | ||
c9b68ede EW |
11 | #include "ww.h" |
12 | ||
f931a8a0 EW |
13 | /* |
14 | * To satisfy Chris, we allocate pty's backwards, and if | |
15 | * there are more than the ptyp's (i.e. the ptyq's) | |
16 | * on the machine, we don't use the p's. | |
17 | */ | |
c9b68ede | 18 | wwgetpty(w) |
c2acc030 | 19 | register struct ww *w; |
c9b68ede EW |
20 | { |
21 | register char c; | |
c9b68ede | 22 | register int i; |
c2acc030 | 23 | int tty; |
8fa6d94c | 24 | int on = 1; |
e840e654 | 25 | char hasq = 0; |
c2acc030 EW |
26 | #define PTY "/dev/XtyXX" |
27 | #define _PT 5 | |
28 | #define _PQRS 8 | |
29 | #define _0_9 9 | |
c9b68ede | 30 | |
c2acc030 | 31 | (void) strcpy(w->ww_ttyname, PTY); |
f931a8a0 | 32 | for (c = 's'; c >= 'p'; c--) { |
c2acc030 EW |
33 | w->ww_ttyname[_PT] = 'p'; |
34 | w->ww_ttyname[_PQRS] = c; | |
35 | w->ww_ttyname[_0_9] = '0'; | |
36 | if (access(w->ww_ttyname, 0) < 0) | |
f931a8a0 | 37 | continue; |
e840e654 EW |
38 | if (c != 'p') |
39 | hasq = 1; | |
40 | else if (hasq) | |
c9b68ede | 41 | break; |
f931a8a0 | 42 | for (i = 15; i >= 0; i--) { |
c2acc030 EW |
43 | w->ww_ttyname[_PT] = 'p'; |
44 | w->ww_ttyname[_0_9] = "0123456789abcdef"[i]; | |
45 | if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0) | |
46 | continue; | |
47 | w->ww_ttyname[_PT] = 't'; | |
48 | if ((tty = open(w->ww_ttyname, 2)) < 0) { | |
49 | (void) close(w->ww_pty); | |
50 | continue; | |
c9b68ede | 51 | } |
c2acc030 | 52 | (void) close(tty); |
e1323162 | 53 | if (ioctl(w->ww_pty, (int)TIOCPKT, (char *)&on) < 0) { |
8fa6d94c EW |
54 | (void) close(w->ww_pty); |
55 | continue; | |
56 | } | |
c2acc030 | 57 | return 0; |
c9b68ede EW |
58 | } |
59 | } | |
eec72f58 | 60 | w->ww_pty = -1; |
03e75950 | 61 | wwerrno = WWE_NOPTY; |
c9b68ede | 62 | return -1; |
c9b68ede | 63 | } |