#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main(argc, argv)
int argc;
char *argv[];
{
struct stat sb;
char *tty;
int ch;
while ((ch = getopt(argc, argv, "")) != EOF)
switch (ch) {
case '?':
default:
goto usage;
}
argc -= optind;
argv += optind;
if ((tty = ttyname(STDERR_FILENO)) == NULL)
err(1, "ttyname");
if (stat(tty, &sb) < 0)
err(1, "%s", tty);
if (*argv == NULL) {
if (sb.st_mode & S_IWGRP) {
(void)fprintf(stderr, "is y\n");
exit(0);
}
(void)fprintf(stderr, "is n\n");
exit(1);
}
switch (*argv[0]) {
case 'y':
if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
err(1, "%s", tty);
exit(0);
case 'n':
if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
err(1, "%s", tty);
exit(1);
}
usage: (void)fprintf(stderr, "usage: mesg [y | n]\n");
exit(2);
}