Annotation of researchv10no/cmd/tty.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Type tty name
        !             3:  */
        !             4: #include <stdio.h>
        !             5: #include <sys/types.h>
        !             6: #include <sys/stat.h>
        !             7: 
        !             8: char   *ttyname();
        !             9: char   *Xttyname();
        !            10: int sts;
        !            11: 
        !            12: main(argc, argv)
        !            13: char **argv;
        !            14: {
        !            15:        register char *p;
        !            16: 
        !            17:        p = Xttyname(0);
        !            18:        if (!(argc==2 && strcmp(argv[1], "-s") == 0))
        !            19:                printf("%s\n", (p? p: "not a tty"));
        !            20:        exit(sts);
        !            21: }
        !            22: 
        !            23: char *
        !            24: Xttyname(fd)
        !            25: int fd;
        !            26: {
        !            27:        struct stat st;
        !            28:        static char buf[20];
        !            29:        char *p;
        !            30: 
        !            31:        sts = 0;
        !            32:        if ((p = ttyname(fd)) != NULL)
        !            33:                return (p);
        !            34:        sts = 1;
        !            35:        if (fstat(fd, &st) < 0)
        !            36:                return (NULL);
        !            37:        if (st.st_nlink != 0)   /* hack -- is it a pipe? */
        !            38:                return (NULL);
        !            39:        sts = 2;
        !            40:        sprintf(buf, "nameless pipe/p%04x", st.st_ino);
        !            41:        return (buf);
        !            42: }

unix.superglobalmegacorp.com

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