BSD 3 development
[unix-history] / usr / src / cmd / mesg.c
CommitLineData
dcc4b875
BJ
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
14struct stat sbuf;
15
16char *tty;
17char *ttyname();
18
19main(argc, argv)
20char *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
46error(s)
47char *s;
48{
49 fprintf(stderr,"mesg: %s\n",s);
50 exit(-1);
51}
52
53newmode(m)
54{
55 if(chmod(tty,m)<0)
56 error("cannot change mode");
57}