From 69d8f2f48010f00f66f6e8d555f2655157ea48df Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Thu, 2 Oct 1980 01:27:25 -0800 Subject: [PATCH] date and time created 80/10/01 17:27:25 by bill SCCS-vsn: usr.bin/mesg/mesg.c 4.1 --- usr/src/usr.bin/mesg/mesg.c | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 usr/src/usr.bin/mesg/mesg.c diff --git a/usr/src/usr.bin/mesg/mesg.c b/usr/src/usr.bin/mesg/mesg.c new file mode 100644 index 0000000000..0b67a9f8fc --- /dev/null +++ b/usr/src/usr.bin/mesg/mesg.c @@ -0,0 +1,58 @@ +static char *sccsid = "@(#)mesg.c 4.1 (Berkeley) %G%"; +/* + * mesg -- set current tty to accept or + * forbid write permission. + * + * mesg [y] [n] + * y allow messages + * n forbid messages + */ + +#include +#include +#include + +struct stat sbuf; + +char *tty; +char *ttyname(); + +main(argc, argv) +char *argv[]; +{ + int r=0; + tty = ttyname(2); + if (tty == 0) + exit(13); + 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"); +} -- 2.20.1