/* * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * %sccs.include.redist.c% */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1987, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)mesg.c 8.2 (Berkeley) 01/21/94"; #endif /* not lint */ #include #include #include #include #include #include #include #include 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); }