Annotation of 3BSD/cmd/mesg.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * mesg -- set current tty to accept or
        !             3:  *     forbid write permission.
        !             4:  *
        !             5:  *     mesg [y] [n]
        !             6:  *             y allow messages
        !             7:  *             n forbid messages
        !             8:  */
        !             9: 
        !            10: #include <stdio.h>
        !            11: #include <sys/types.h>
        !            12: #include <sys/stat.h>
        !            13: 
        !            14: struct stat sbuf;
        !            15: 
        !            16: char *tty;
        !            17: char *ttyname();
        !            18: 
        !            19: main(argc, argv)
        !            20: char *argv[];
        !            21: {
        !            22:        int r=0;
        !            23:        tty = ttyname(2);
        !            24:        if (tty == 0)
        !            25:                exit(13);
        !            26:        if(stat(tty, &sbuf) < 0) error("cannot stat");
        !            27:        if(argc < 2) {
        !            28:                if(sbuf.st_mode & 02)
        !            29:                        fprintf(stderr,"is y\n");
        !            30:                else {  r=1;
        !            31:                        fprintf(stderr,"is n\n");
        !            32:                }
        !            33:        } else  switch(*argv[1]) {
        !            34:                case 'y':
        !            35:                        newmode(0622); break;
        !            36: 
        !            37:                case 'n':
        !            38:                        newmode(0600); r=1; break;
        !            39: 
        !            40:                default:
        !            41:                        error("usage: mesg [y] [n]");
        !            42:                }
        !            43:        exit(r);
        !            44: }
        !            45: 
        !            46: error(s)
        !            47: char *s;
        !            48: {
        !            49:        fprintf(stderr,"mesg: %s\n",s);
        !            50:        exit(-1);
        !            51: }
        !            52: 
        !            53: newmode(m)
        !            54: {
        !            55:        if(chmod(tty,m)<0)
        !            56:                error("cannot change mode");
        !            57: }

unix.superglobalmegacorp.com

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