h63754
s 00055/00000/00000
d D 1.1 82/08/02 15:44:16 cecily 1 0
e
u
U
t
T
I 1
/*
 * mesg -- set current tty to accept or
 *	forbid write permission.
 *
 *	mesg [y] [n]
 *		y allow messages
 *		n forbid messages
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

struct stat sbuf;

char *tty;
char *ttyname();

main(argc, argv)
char *argv[];
{
	int r=0;
	tty = ttyname(2);
	if(stat(tty, &sbuf) < 0) error("cannot stat");
	if(argc < 2) {
		if(sbuf.st_mode & 02)
			fprintf(stderr,"is y\n");
		else {	r=1;
			fprintf(stderr,"is n\n");
		}
	} else	switch(*argv[1]) {
		case 'y':
			newmode(0622); break;

		case 'n':
			newmode(0600); r=1; break;

		default:
			error("usage: mesg [y] [n]");
		}
	exit(r);
}

error(s)
char *s;
{
	fprintf(stderr,"mesg: %s\n",s);
	exit(-1);
}

newmode(m)
{
	if(chmod(tty,m)<0)
		error("cannot change mode");
}
E 1
