Commit | Line | Data |
---|---|---|
3b600ead TL |
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(stat(tty, &sbuf) < 0) error("cannot stat"); | |
25 | if(argc < 2) { | |
26 | if(sbuf.st_mode & 02) | |
27 | fprintf(stderr,"is y\n"); | |
28 | else { r=1; | |
29 | fprintf(stderr,"is n\n"); | |
30 | } | |
31 | } else switch(*argv[1]) { | |
32 | case 'y': | |
33 | newmode(0622); break; | |
34 | ||
35 | case 'n': | |
36 | newmode(0600); r=1; break; | |
37 | ||
38 | default: | |
39 | error("usage: mesg [y] [n]"); | |
40 | } | |
41 | exit(r); | |
42 | } | |
43 | ||
44 | error(s) | |
45 | char *s; | |
46 | { | |
47 | fprintf(stderr,"mesg: %s\n",s); | |
48 | exit(-1); | |
49 | } | |
50 | ||
51 | newmode(m) | |
52 | { | |
53 | if(chmod(tty,m)<0) | |
54 | error("cannot change mode"); | |
55 | } |