Annotation of coherent/b/lib/libc/gen/ttyname.c, revision 1.1

1.1     ! root        1: #define        NEWTTYS 1
        !             2: /*
        !             3:  * libc/gen/ttyname.c
        !             4:  * Coherent I/O Library.
        !             5:  * Return the name of the terminal device
        !             6:  * associated with the given file descriptor.
        !             7:  * The names in /etc/ttys define the domain.
        !             8:  */
        !             9: 
        !            10: #include <limits.h>
        !            11: #include <stdio.h>
        !            12: #include <string.h>
        !            13: #include <sys/stat.h>
        !            14: 
        !            15: static char dev_buff [PATH_MAX + 8] = "/dev/console";
        !            16: 
        !            17: char *
        !            18: ttyname(fd) int fd;
        !            19: {
        !            20:        if (_ttyslot (fd) >= 0)
        !            21:                return dev_buff;
        !            22:        return NULL;
        !            23: }
        !            24: 
        !            25: /*
        !            26:  * Return the /etc/ttys slot for fd, -1 on error.
        !            27:  * The /dev/... name is left in dev_buff.
        !            28:  * Used by ttyname() and ttyslot().
        !            29:  */
        !            30: int
        !            31: _ttyslot(fd) int fd;
        !            32: {
        !            33:        register FILE *fp;
        !            34:        register short fd_mode;
        !            35:        register dev_t fd_rdev;
        !            36:        register int slot;
        !            37:        struct stat sb;
        !            38: 
        !            39:        if (fstat(fd, &sb) < 0 ||
        !            40:            (fp = fopen("/etc/ttys", "r")) == NULL)
        !            41:                return -1;
        !            42:        fd_mode = sb.st_mode;
        !            43:        fd_rdev = sb.st_rdev;
        !            44:        for (slot = 0; ; slot += 1) {
        !            45:                if (getc (fp) == '\n' || /* Missing status */
        !            46: #if NEWTTYS
        !            47:                    getc (fp) == '\n' || /* Missing line type, ie loc or rem */
        !            48: #endif
        !            49:                    getc (fp) == '\n' ||        /* Missing getty arg */
        !            50:                    fgets (dev_buff + 5, NAME_MAX, fp) == NULL ||
        !            51:                    strchr (dev_buff, '\n') == NULL) {
        !            52:                        slot = -1;
        !            53:                        break;
        !            54:                }
        !            55:                * strchr (dev_buff, '\n') = 0;
        !            56:                if (stat (dev_buff, & sb) >= 0 && sb.st_mode == fd_mode &&
        !            57:                    sb.st_rdev == fd_rdev)
        !            58:                        break;
        !            59:        }
        !            60:        fclose (fp);
        !            61:        return slot;
        !            62: }
        !            63: 
        !            64: /* end of libc/gen/ttyname.c */

unix.superglobalmegacorp.com

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