date and time created 83/08/09 18:37:53 by edward
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Wed, 10 Aug 1983 09:37:53 +0000 (01:37 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Wed, 10 Aug 1983 09:37:53 +0000 (01:37 -0800)
SCCS-vsn: usr.bin/window/wwpty.c 3.1

usr/src/usr.bin/window/wwpty.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/window/wwpty.c b/usr/src/usr.bin/window/wwpty.c
new file mode 100644 (file)
index 0000000..eff0ec4
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef lint
+static char *sccsid = "@(#)wwpty.c     3.1 83/08/09";
+#endif
+
+#include "ww.h"
+
+wwgetpty(w)
+       register struct ww *w;
+{
+       register char c;
+       register char *line;
+       register int i;
+#define PTY "/dev/ptyXX"
+
+       for (c = 'p'; c <= 's'; c++) {
+               line = PTY;
+               line[sizeof PTY - 6] = 'p';
+               line[sizeof PTY - 3] = c;
+               line[sizeof PTY - 2] = '0';
+               if (access(line, 0) < 0)
+                       break;
+               for (i = 0; i < 16; i++) {
+                       line[sizeof PTY - 6] = 'p';
+                       line[sizeof PTY - 2] = "0123456789abcdef"[i];
+                       w->ww_pty = open(line, 2);
+                       if (w->ww_pty >= 0) {
+                               line[sizeof PTY - 6] = 't';
+                               w->ww_tty = open(line, 2);
+                               if (w->ww_tty >= 0)
+                                       goto good;
+                               (void) close(w->ww_pty);
+                       }
+               }
+       }
+       return -1;
+good:
+       (void) strcpy(w->ww_ttyname, line);
+       return 0;
+}