1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1980, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)biff.c 8.2 (Berkeley) 04/29/95";
16 #endif /* not lint */
17
18 #include <sys/types.h>
19 #include <sys/stat.h>
20
21 #include <err.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 static void usage __P((void));
29
30 int
main(argc,argv)31 main(argc, argv)
32 int argc;
33 char *argv[];
34 {
35 struct stat sb;
36 int ch;
37 char *name;
38
39 while ((ch = getopt(argc, argv, "")) != EOF)
40 switch(ch) {
41 case '?':
42 default:
43 usage();
44 }
45 argc -= optind;
46 argv += optind;
47
48 if ((name = ttyname(STDERR_FILENO)) == NULL)
49 err(2, "tty");
50
51 if (stat(name, &sb))
52 err(2, "stat");
53
54 if (*argv == NULL) {
55 (void)printf("is %s\n", sb.st_mode&0100 ? "y" : "n");
56 exit(sb.st_mode & 0100 ? 0 : 1);
57 }
58
59 switch(argv[0][0]) {
60 case 'n':
61 if (chmod(name, sb.st_mode & ~0100) < 0)
62 err(2, name);
63 break;
64 case 'y':
65 if (chmod(name, sb.st_mode | 0100) < 0)
66 err(2, name);
67 break;
68 default:
69 usage();
70 }
71 exit(sb.st_mode & 0100 ? 0 : 1);
72 }
73
74 static void
usage()75 usage()
76 {
77 (void)fprintf(stderr, "usage: biff [y | n]\n");
78 exit(2);
79 }
80