libutil: add O_NOCTTY to old pty open code
[minix3.git] / commands / mesg / mesg.c
blob2fb3d71556c99564b9d593e591377c726530b4ba
1 /* mesg - enable or disable communications. Author: John J. Ribera */
3 /*
4 * mesg - enable or disable communications.
6 * Usage: mesg [ y | n ]
8 * 'mesg n' will turn off group and world permissions of the
9 * user's terminal.
10 * 'mesg y' will enable group and world to write to the user's
11 * tty.
12 * mesg with no parameters will put the writeable status
13 * onto stdout.
15 * Author: John J. Ribera, Jr. 09/09/90
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
23 int main(int argc, char *argv []);
25 int main(argc, argv)
26 int argc;
27 char *argv[];
29 struct stat statb;
30 char *tty_name;
32 if ((tty_name = ttyname(0)) == NULL) exit(2);
33 if (stat(tty_name, &statb) == -1) exit(2);
34 if (--argc) {
35 if (*argv[1] == 'n') statb.st_mode = 0600;
36 else if (*argv[1] == 'y') statb.st_mode = 0620;
37 else {
38 fprintf(stderr, "mesg: usage: mesg [n|y]\n");
39 exit(2);
41 if (chmod(tty_name, statb.st_mode) == -1) exit(2);
42 } else printf((statb.st_mode & 020) ? "is y\n" : "is n\n");
44 if (statb.st_mode & 020) exit(0);
46 exit(1);