Annotation of coherent/d/lib/libc/gen/ttyname.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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