Annotation of coherent/g/usr/lib/misc/getpty.c, revision 1.1

1.1     ! root        1: #include <errno.h>
        !             2: #include <fcntl.h>
        !             3: 
        !             4: static char PtyName[32] = "/dev/ptyXY";
        !             5: static char TtyName[32] = "/dev/ttyXY";
        !             6: 
        !             7: /*
        !             8:  * Claim a pseudo-tty.
        !             9:  * Takes pointers to buffers for the names of the newly claimed pair
        !            10:  * and returns a file descriptor on the open pty.
        !            11:  *
        !            12:  * Returns -1 on any sort of failure.  errno will be set to ENXIO
        !            13:  * if there were no more ptys.
        !            14:  */
        !            15: int
        !            16: getpseudotty(newtty, newpty)
        !            17:        char *newtty, *newpty;
        !            18: {
        !            19:        register char *l, *d;
        !            20:        int X, Y, f;
        !            21:    
        !            22:        /*
        !            23:         * Locate the "XY" in the above strings.
        !            24:         */
        !            25:        X = strlen(PtyName) - 2;
        !            26:        Y = X + 1;
        !            27: 
        !            28:        /*
        !            29:         * Walk through all possible values of X.
        !            30:         */
        !            31:        for (l = "pqrstuvwxyz"; '\0' != *l; ++l) {
        !            32:                PtyName[X] = *l;
        !            33:                /*
        !            34:                 * Walk through all possible values of Y.
        !            35:                 */
        !            36:                for (d = "0123456789abcdef"; *d; ++d) {
        !            37:                        PtyName[Y] = *d;
        !            38:                        /*
        !            39:                         * If we can open() the pty, it means we have
        !            40:                         * claimed it.
        !            41:                         */
        !            42:                        if ((f = open(PtyName, O_RDWR)) != -1) {
        !            43:                                /*
        !            44:                                 * Return the name of the pty.
        !            45:                                 */
        !            46:                                strcpy(newpty, PtyName);
        !            47:                                /*
        !            48:                                 * Build and return the name of the tty.
        !            49:                                 */
        !            50:                                TtyName[X] = *l;
        !            51:                                TtyName[Y] = *d;
        !            52:                                strcpy(newtty, TtyName);
        !            53:                                return f;
        !            54:                        } else if(errno == ENXIO) {
        !            55:                                /*
        !            56:                                 * No more ptys!
        !            57:                                 */
        !            58:                                break;
        !            59:                        }
        !            60:                }
        !            61:        }
        !            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.