Commit | Line | Data |
---|---|---|
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 | |
5e8b0e60 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
60de5df9 EW |
16 | */ |
17 | ||
46e9ea25 | 18 | #ifndef lint |
5e8b0e60 | 19 | static char sccsid[] = "@(#)wwpty.c 3.15 (Berkeley) %G%"; |
46e9ea25 KB |
20 | #endif /* not lint */ |
21 | ||
c9b68ede EW |
22 | #include "ww.h" |
23 | ||
24 | wwgetpty(w) | |
c2acc030 | 25 | register struct ww *w; |
c9b68ede | 26 | { |
01135bd2 | 27 | register char c, *p; |
c2acc030 | 28 | int tty; |
8fa6d94c | 29 | int on = 1; |
c2acc030 EW |
30 | #define PTY "/dev/XtyXX" |
31 | #define _PT 5 | |
32 | #define _PQRS 8 | |
33 | #define _0_9 9 | |
c9b68ede | 34 | |
c2acc030 | 35 | (void) strcpy(w->ww_ttyname, PTY); |
01135bd2 | 36 | for (c = 'p'; c <= 'u'; c++) { |
c2acc030 EW |
37 | w->ww_ttyname[_PT] = 'p'; |
38 | w->ww_ttyname[_PQRS] = c; | |
39 | w->ww_ttyname[_0_9] = '0'; | |
40 | if (access(w->ww_ttyname, 0) < 0) | |
c9b68ede | 41 | break; |
01135bd2 | 42 | for (p = "0123456789abcdef"; *p; p++) { |
c2acc030 | 43 | w->ww_ttyname[_PT] = 'p'; |
01135bd2 | 44 | w->ww_ttyname[_0_9] = *p; |
c2acc030 EW |
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); |
20029082 | 53 | if (ioctl(w->ww_pty, 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 | } |