added "more" command
[unix-history] / usr / src / usr.bin / mesg / mesg.c
CommitLineData
76f20214 1static char *sccsid = "@(#)mesg.c 4.2 (Berkeley) %G%";
69d8f2f4
BJ
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
15struct stat sbuf;
16
17char *tty;
18char *ttyname();
19
20main(argc, argv)
21char *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':
76f20214 36 newmode(sbuf.st_mode|022); break;
69d8f2f4
BJ
37
38 case 'n':
76f20214 39 newmode(sbuf.st_mode&~022); r=1; break;
69d8f2f4
BJ
40
41 default:
42 error("usage: mesg [y] [n]");
43 }
44 exit(r);
45}
46
47error(s)
48char *s;
49{
50 fprintf(stderr,"mesg: %s\n",s);
51 exit(-1);
52}
53
54newmode(m)
55{
56 if(chmod(tty,m)<0)
57 error("cannot change mode");
58}