a432b5eb5d8987d7d0751fe4180a96ef96618f57
[unix-history] / usr / src / usr.bin / mesg / mesg.c
/*
* Copyright (c) 1987, 1993 Regents of the University of California.
* All rights reserved.
*
* %sccs.include.redist.c%
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1987, 1993 Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mesg.c 5.4 (Berkeley) %G%";
#endif /* not lint */
#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);
}