Annotation of 43BSD/ucb/window/wwpty.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)wwpty.c    3.11 4/24/85";
                      3: #endif
                      4: 
                      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: 
                     11: #include "ww.h"
                     12: 
                     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:  */
                     18: wwgetpty(w)
                     19: register struct ww *w;
                     20: {
                     21:        register char c;
                     22:        register int i;
                     23:        int tty;
                     24:        int on = 1;
                     25:        char hasq = 0;
                     26: #define PTY "/dev/XtyXX"
                     27: #define _PT    5
                     28: #define _PQRS  8
                     29: #define _0_9   9
                     30: 
                     31:        (void) strcpy(w->ww_ttyname, PTY);
                     32:        for (c = 's'; c >= 'p'; c--) {
                     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)
                     37:                        continue;
                     38:                if (c != 'p')
                     39:                        hasq = 1;
                     40:                else if (hasq)
                     41:                        break;
                     42:                for (i = 15; i >= 0; i--) {
                     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;
                     51:                        }
                     52:                        (void) close(tty);
                     53:                        if (ioctl(w->ww_pty, (int)TIOCPKT, (char *)&on) < 0) {
                     54:                                (void) close(w->ww_pty);
                     55:                                continue;
                     56:                        }
                     57:                        return 0;
                     58:                }
                     59:        }
                     60:        w->ww_pty = -1;
                     61:        wwerrno = WWE_NOPTY;
                     62:        return -1;
                     63: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.