121547Sdist /*
261927Sbostic * Copyright (c) 1980, 1993
361927Sbostic * The Regents of the University of California. All rights reserved.
435511Sbostic *
542720Sbostic * %sccs.include.redist.c%
621547Sdist */
721547Sdist
813618Ssam #ifndef lint
961927Sbostic static char copyright[] =
1061927Sbostic "@(#) Copyright (c) 1980, 1993\n\
1161927Sbostic The Regents of the University of California. All rights reserved.\n";
1235511Sbostic #endif /* not lint */
1321547Sdist
1421547Sdist #ifndef lint
15*69114Sbostic static char sccsid[] = "@(#)biff.c 8.2 (Berkeley) 04/29/95";
1635511Sbostic #endif /* not lint */
1721547Sdist
181527Sbill #include <sys/types.h>
1913618Ssam #include <sys/stat.h>
20*69114Sbostic
21*69114Sbostic #include <err.h>
2250557Sbostic #include <errno.h>
231527Sbill #include <stdio.h>
2450557Sbostic #include <stdlib.h>
2550557Sbostic #include <string.h>
26*69114Sbostic #include <unistd.h>
271527Sbill
2850557Sbostic static void usage __P((void));
291527Sbill
30*69114Sbostic int
main(argc,argv)311527Sbill main(argc, argv)
321527Sbill int argc;
3350557Sbostic char *argv[];
341527Sbill {
3550557Sbostic struct stat sb;
3650557Sbostic int ch;
3750557Sbostic char *name;
381527Sbill
3950557Sbostic while ((ch = getopt(argc, argv, "")) != EOF)
4050557Sbostic switch(ch) {
4150557Sbostic case '?':
4250557Sbostic default:
4350557Sbostic usage();
4450557Sbostic }
4550557Sbostic argc -= optind;
4650557Sbostic argv += optind;
4750557Sbostic
48*69114Sbostic if ((name = ttyname(STDERR_FILENO)) == NULL)
49*69114Sbostic err(2, "tty");
501527Sbill
5150557Sbostic if (stat(name, &sb))
52*69114Sbostic err(2, "stat");
531527Sbill
5450557Sbostic if (*argv == NULL) {
5550557Sbostic (void)printf("is %s\n", sb.st_mode&0100 ? "y" : "n");
5650557Sbostic exit(sb.st_mode & 0100 ? 0 : 1);
5750557Sbostic }
5850557Sbostic
5950557Sbostic switch(argv[0][0]) {
601527Sbill case 'n':
6150557Sbostic if (chmod(name, sb.st_mode & ~0100) < 0)
62*69114Sbostic err(2, name);
631527Sbill break;
6450557Sbostic case 'y':
6550557Sbostic if (chmod(name, sb.st_mode | 0100) < 0)
66*69114Sbostic err(2, name);
6750557Sbostic break;
681527Sbill default:
6950557Sbostic usage();
701527Sbill }
7150557Sbostic exit(sb.st_mode & 0100 ? 0 : 1);
721527Sbill }
7350557Sbostic
7450557Sbostic static void
usage()7550557Sbostic usage()
7650557Sbostic {
7750557Sbostic (void)fprintf(stderr, "usage: biff [y | n]\n");
7850557Sbostic exit(2);
7950557Sbostic }
80