Research V6 development
authorDennis Ritchie <dmr@research.uucp>
Wed, 14 May 1975 00:49:58 +0000 (19:49 -0500)
committerDennis Ritchie <dmr@research.uucp>
Wed, 14 May 1975 00:49:58 +0000 (19:49 -0500)
Work on file usr/source/s2/mesg.c

Co-Authored-By: Ken Thompson <ken@research.uucp>
Synthesized-from: v6

usr/source/s2/mesg.c [new file with mode: 0644]

diff --git a/usr/source/s2/mesg.c b/usr/source/s2/mesg.c
new file mode 100644 (file)
index 0000000..efde97e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * mesg -- set current tty to accept or
+ *     forbid write permission.
+ *
+ *     mesg [y] [n]
+ *             y allow messages
+ *             n forbid messages
+ */
+
+int    sbuf[40];
+
+main(argc, argv)
+char *argv[];
+{
+       register char *tty;
+
+       tty = "/dev/ttyx";
+       tty[8] = ttyn(1);
+       if(stat(tty, sbuf) < 0) {
+               write(2, "cannot stat\n", 12);
+               exit(1);
+       }
+       if(argc < 2) {
+               if(sbuf[2] & 02)
+                       goto no;
+               goto yes;
+       }
+       if(*argv[1] == 'y')
+               goto yes;
+
+no:
+       if(chmod(tty, 0600) < 0)
+               goto bad;
+       goto was;
+
+yes:
+       if(chmod(tty, 0622) < 0)
+               goto bad;
+
+was:
+       if(sbuf[2] & 02)
+               write(2, "was y\n", 6); else
+               write(2, "was n\n", 6);
+       exit(0);
+
+bad:
+       write(2, "cannot change mode\n", 19);
+       exit(1);
+}