Annotation of researchv9/libc/gen/ptopen.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     fd = ptopen (buf)
                      3:  *
                      4:  *     Attempt to open an odd pt - if successful, return the
                      5:  *     file descriptor in fd and place the name of the corresponding
                      6:  *     even pt in buf.  Buf must be large enough.
                      7:  *
                      8:  *     We assume that the digits 0-9 are consecutive in the
                      9:  *     machine's character set.
                     10:  */
                     11: 
                     12: #include <errno.h>
                     13: 
                     14: #define PTNAME "/dev/pt/pt01"
                     15: 
                     16: extern int errno;
                     17: 
                     18: int
                     19: ptopen (name)
                     20:        char *name;
                     21: {
                     22:        register int fd;
                     23:        register char *p, *q;
                     24: 
                     25:        /*
                     26:         *      copy the initial name to user's buffer
                     27:         *      leave p pointing at the last character
                     28:         */
                     29:        p = name;
                     30:        q = PTNAME;
                     31:        while ((*p++ = *q++) != '\0')
                     32:                ;
                     33:        p -= 2;
                     34:        
                     35:        /* try to open pt files until success or we run out */
                     36:        for (;;) {
                     37:                fd = open (name, 2);
                     38: 
                     39:                /* check for success */
                     40:                if (fd >= 0) {
                     41:                        --*p;
                     42:                        return fd;
                     43:                }
                     44: 
                     45:                /* check for run-out */
                     46:                if (errno != ENXIO)
                     47:                        return -1;
                     48: 
                     49:                /* this pt is busy, try the next */
                     50:                if (*p != '9')
                     51:                        *p += 2;
                     52:                else {
                     53:                        /* propagate carry from low-order digit */
                     54:                        *p = '1';
                     55:                        q = p - 1;
                     56:                        while (*q == '9')
                     57:                                *q-- = '0';
                     58:                        if (*q >= '0' && *q <= '9')
                     59:                                ++*q;
                     60:                        else {
                     61:                                /* insert a leading digit */
                     62:                                register char *r = ++p;
                     63:                                while (r > q) {
                     64:                                        r[1] = r[0];
                     65:                                        --r;
                     66:                                }
                     67:                                q[1] = '1';
                     68:                        }
                     69:                }
                     70:        }
                     71: }

unix.superglobalmegacorp.com

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