error reporting
[unix-history] / usr / src / usr.bin / window / wwpty.c
CommitLineData
c9b68ede 1#ifndef lint
03e75950 2static char *sccsid = "@(#)wwpty.c 3.3 83/08/26";
c9b68ede
EW
3#endif
4
5#include "ww.h"
6
7wwgetpty(w)
8 register struct ww *w;
9{
10 register char c;
11 register char *line;
12 register int i;
13#define PTY "/dev/ptyXX"
14
15 for (c = 'p'; c <= 's'; c++) {
16 line = PTY;
17 line[sizeof PTY - 6] = 'p';
18 line[sizeof PTY - 3] = c;
19 line[sizeof PTY - 2] = '0';
20 if (access(line, 0) < 0)
21 break;
22 for (i = 0; i < 16; i++) {
23 line[sizeof PTY - 6] = 'p';
24 line[sizeof PTY - 2] = "0123456789abcdef"[i];
25 w->ww_pty = open(line, 2);
26 if (w->ww_pty >= 0) {
27 line[sizeof PTY - 6] = 't';
28 w->ww_tty = open(line, 2);
29 if (w->ww_tty >= 0)
30 goto good;
31 (void) close(w->ww_pty);
32 }
33 }
34 }
03e75950 35 wwerrno = WWE_NOPTY;
c9b68ede
EW
36 return -1;
37good:
38 (void) strcpy(w->ww_ttyname, line);
39 return 0;
40}