1*7e47a120Sjoerg /* $NetBSD: biff.c,v 1.11 2011/08/29 14:24:03 joerg Exp $ */
2b7327c7cSglass
361f28255Scgd /*
4b7327c7cSglass * Copyright (c) 1980, 1993
5b7327c7cSglass * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
1589aaa1bbSagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
3280baf83fSlukem #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
3498e5374cSlukem __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
3598e5374cSlukem The Regents of the University of California. All rights reserved.");
3661f28255Scgd #endif /* not lint */
3761f28255Scgd
3861f28255Scgd #ifndef lint
39b7327c7cSglass #if 0
40b7327c7cSglass static char sccsid[] = "@(#)biff.c 8.1 (Berkeley) 6/6/93";
41b7327c7cSglass #else
42*7e47a120Sjoerg __RCSID("$NetBSD: biff.c,v 1.11 2011/08/29 14:24:03 joerg Exp $");
43b7327c7cSglass #endif
4461f28255Scgd #endif /* not lint */
4561f28255Scgd
4661f28255Scgd #include <sys/types.h>
4761f28255Scgd #include <sys/stat.h>
4861f28255Scgd
49b7327c7cSglass #include <err.h>
50b7327c7cSglass #include <errno.h>
51b7327c7cSglass #include <stdio.h>
52b7327c7cSglass #include <stdlib.h>
53b7327c7cSglass #include <string.h>
54b7327c7cSglass #include <unistd.h>
55b7327c7cSglass
56*7e47a120Sjoerg __dead static void usage(void);
5761f28255Scgd
5880baf83fSlukem int
main(int argc,char * argv[])59971b39dfSxtraeme main(int argc, char *argv[])
6061f28255Scgd {
61b7327c7cSglass struct stat sb;
62b7327c7cSglass int ch;
63519d8585Smycroft const char *name;
6461f28255Scgd
6561f28255Scgd
669992ac3eSlukem while ((ch = getopt(argc, argv, "")) != -1)
67b7327c7cSglass switch(ch) {
68b7327c7cSglass case '?':
6961f28255Scgd default:
70b7327c7cSglass usage();
7161f28255Scgd }
72b7327c7cSglass argc -= optind;
73b7327c7cSglass argv += optind;
74b7327c7cSglass
75b7327c7cSglass if ((name = ttyname(STDERR_FILENO)) == NULL)
76b7327c7cSglass err(2, "tty");
77b7327c7cSglass
78b7327c7cSglass if (stat(name, &sb))
79b7327c7cSglass err(2, "stat");
80b7327c7cSglass
81b7327c7cSglass if (*argv == NULL) {
82b7327c7cSglass (void)printf("is %s\n", sb.st_mode&0100 ? "y" : "n");
83b7327c7cSglass exit(sb.st_mode & 0100 ? 0 : 1);
84b7327c7cSglass }
85b7327c7cSglass
86b7327c7cSglass switch(argv[0][0]) {
87b7327c7cSglass case 'n':
88b7327c7cSglass if (chmod(name, sb.st_mode & ~0100) < 0)
89bbef2fbaSitojun err(2, "%s", name);
90b7327c7cSglass break;
91b7327c7cSglass case 'y':
92b7327c7cSglass if (chmod(name, sb.st_mode | 0100) < 0)
93bbef2fbaSitojun err(2, "%s", name);
94b7327c7cSglass break;
95b7327c7cSglass default:
96b7327c7cSglass usage();
97b7327c7cSglass }
98b7327c7cSglass exit(sb.st_mode & 0100 ? 0 : 1);
99b7327c7cSglass }
100b7327c7cSglass
101b7327c7cSglass static void
usage(void)102971b39dfSxtraeme usage(void)
103b7327c7cSglass {
104b7327c7cSglass (void)fprintf(stderr, "usage: biff [y | n]\n");
105b7327c7cSglass exit(2);
10661f28255Scgd }
107