Annotation of 40BSD/cmd/mesg.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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