biff.c revision 26836
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1980, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 3. All advertising materials mentioning features or use of this software
141590Srgrimes *    must display the following acknowledgement:
151590Srgrimes *	This product includes software developed by the University of
161590Srgrimes *	California, Berkeley and its contributors.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
3226836Scharnier *
3326836Scharnier *	$Id$
341590Srgrimes */
351590Srgrimes
361590Srgrimes#ifndef lint
371590Srgrimesstatic char copyright[] =
381590Srgrimes"@(#) Copyright (c) 1980, 1993\n\
391590Srgrimes	The Regents of the University of California.  All rights reserved.\n";
401590Srgrimes#endif /* not lint */
411590Srgrimes
421590Srgrimes#ifndef lint
431590Srgrimesstatic char sccsid[] = "@(#)biff.c	8.1 (Berkeley) 6/6/93";
441590Srgrimes#endif /* not lint */
451590Srgrimes
461590Srgrimes#include <sys/types.h>
471590Srgrimes#include <sys/stat.h>
481590Srgrimes#include <errno.h>
491590Srgrimes#include <unistd.h>
501590Srgrimes#include <stdio.h>
511590Srgrimes#include <stdlib.h>
521590Srgrimes#include <string.h>
5326836Scharnier#include <err.h>
541590Srgrimes
551590Srgrimesstatic void usage __P((void));
561590Srgrimes
571590Srgrimesmain(argc, argv)
581590Srgrimes	int argc;
591590Srgrimes	char *argv[];
601590Srgrimes{
611590Srgrimes	struct stat sb;
621590Srgrimes	int ch;
631590Srgrimes	char *name;
641590Srgrimes
651590Srgrimes
6624360Simp	while ((ch = getopt(argc, argv, "")) != -1)
671590Srgrimes		switch(ch) {
681590Srgrimes		case '?':
691590Srgrimes		default:
701590Srgrimes			usage();
711590Srgrimes		}
721590Srgrimes	argc -= optind;
731590Srgrimes	argv += optind;
741590Srgrimes
7526836Scharnier	if ((name = ttyname(STDERR_FILENO)) == NULL)
7626836Scharnier		err(2, "unknown tty");
771590Srgrimes
781590Srgrimes	if (stat(name, &sb))
7926836Scharnier		err(2, "stat");
801590Srgrimes
811590Srgrimes	if (*argv == NULL) {
821590Srgrimes		(void)printf("is %s\n", sb.st_mode&0100 ? "y" : "n");
831590Srgrimes		exit(sb.st_mode & 0100 ? 0 : 1);
841590Srgrimes	}
851590Srgrimes
861590Srgrimes	switch(argv[0][0]) {
871590Srgrimes	case 'n':
881590Srgrimes		if (chmod(name, sb.st_mode & ~0100) < 0)
8926836Scharnier			err(2, name);
901590Srgrimes		break;
911590Srgrimes	case 'y':
921590Srgrimes		if (chmod(name, sb.st_mode | 0100) < 0)
9326836Scharnier			err(2, name);
941590Srgrimes		break;
951590Srgrimes	default:
961590Srgrimes		usage();
971590Srgrimes	}
981590Srgrimes	exit(sb.st_mode & 0100 ? 0 : 1);
991590Srgrimes}
1001590Srgrimes
1011590Srgrimesstatic void
1021590Srgrimesusage()
1031590Srgrimes{
1041590Srgrimes	(void)fprintf(stderr, "usage: biff [y | n]\n");
1051590Srgrimes	exit(2);
1061590Srgrimes}
107