| Line | |
|---|
| 1 | /* mesg - enable or disable communications. Author: John J. Ribera */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * mesg - enable or disable communications.
|
|---|
| 5 | *
|
|---|
| 6 | * Usage: mesg [ y | n ]
|
|---|
| 7 | *
|
|---|
| 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.
|
|---|
| 14 | *
|
|---|
| 15 | * Author: John J. Ribera, Jr. 09/09/90
|
|---|
| 16 | */
|
|---|
| 17 | #include <sys/types.h>
|
|---|
| 18 | #include <sys/stat.h>
|
|---|
| 19 | #include <stdio.h>
|
|---|
| 20 | #include <stdlib.h>
|
|---|
| 21 | #include <unistd.h>
|
|---|
| 22 |
|
|---|
| 23 | _PROTOTYPE( int main, (int argc, char *argv []) );
|
|---|
| 24 |
|
|---|
| 25 | int main(argc, argv)
|
|---|
| 26 | int argc;
|
|---|
| 27 | char *argv[];
|
|---|
| 28 | {
|
|---|
| 29 | struct stat statb;
|
|---|
| 30 | char *tty_name;
|
|---|
| 31 |
|
|---|
| 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);
|
|---|
| 40 | }
|
|---|
| 41 | if (chmod(tty_name, statb.st_mode) == -1) exit(2);
|
|---|
| 42 | } else printf((statb.st_mode & 020) ? "is y\n" : "is n\n");
|
|---|
| 43 |
|
|---|
| 44 | if (statb.st_mode & 020) exit(0);
|
|---|
| 45 |
|
|---|
| 46 | exit(1);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.