biff.c revision 100443
138451Smsmith/* 238451Smsmith * Copyright (c) 1980, 1993 338451Smsmith * The Regents of the University of California. All rights reserved. 438451Smsmith * 538451Smsmith * Redistribution and use in source and binary forms, with or without 638451Smsmith * modification, are permitted provided that the following conditions 738451Smsmith * are met: 838451Smsmith * 1. Redistributions of source code must retain the above copyright 938451Smsmith * notice, this list of conditions and the following disclaimer. 1038451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138451Smsmith * notice, this list of conditions and the following disclaimer in the 1238451Smsmith * documentation and/or other materials provided with the distribution. 1338451Smsmith * 3. All advertising materials mentioning features or use of this software 1438451Smsmith * must display the following acknowledgement: 1538451Smsmith * This product includes software developed by the University of 1638451Smsmith * California, Berkeley and its contributors. 1738451Smsmith * 4. Neither the name of the University nor the names of its contributors 1838451Smsmith * may be used to endorse or promote products derived from this software 1938451Smsmith * without specific prior written permission. 2038451Smsmith * 2138451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2238451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2338451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2438451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2538451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2638451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2738451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2838451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2938451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3084221Sdillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3184221Sdillon * SUCH DAMAGE. 3284221Sdillon */ 3338451Smsmith 3438451Smsmith#ifndef lint 3538451Smsmithstatic const char copyright[] = 3638451Smsmith"@(#) Copyright (c) 1980, 1993\n\ 3738451Smsmith The Regents of the University of California. All rights reserved.\n"; 3838451Smsmith#endif 3938451Smsmith 4038451Smsmith#if 0 4138451Smsmith#ifndef lint 4238451Smsmithstatic char sccsid[] = "@(#)biff.c 8.1 (Berkeley) 6/6/93"; 4338451Smsmith#endif 4438451Smsmith#endif 4538451Smsmith 4638451Smsmith#include <sys/cdefs.h> 4738451Smsmith__FBSDID("$FreeBSD: head/usr.bin/biff/biff.c 100443 2002-07-21 15:11:32Z johan $"); 4838451Smsmith 4938451Smsmith#include <sys/stat.h> 5038451Smsmith 5138451Smsmith#include <err.h> 5238451Smsmith#include <stdio.h> 5338451Smsmith#include <stdlib.h> 5438451Smsmith#include <unistd.h> 55221358Srodrigc 5638451Smsmithstatic void usage(void); 5738451Smsmith 5838451Smsmithint 5938451Smsmithmain(argc, argv) 6038451Smsmith int argc; 6138451Smsmith char *argv[]; 6238451Smsmith{ 6338451Smsmith struct stat sb; 6438451Smsmith int ch; 6538451Smsmith char *name; 6638451Smsmith 6738451Smsmith 6838451Smsmith while ((ch = getopt(argc, argv, "")) != -1) 6938451Smsmith switch(ch) { 7038451Smsmith case '?': 7138451Smsmith default: 7238451Smsmith usage(); 7338451Smsmith } 7438451Smsmith argc -= optind; 7538451Smsmith argv += optind; 7638451Smsmith 7738451Smsmith if ((name = ttyname(STDERR_FILENO)) == NULL) 7838451Smsmith err(2, "unknown tty"); 7938451Smsmith 8038451Smsmith if (stat(name, &sb)) 8138451Smsmith err(2, "stat"); 8238451Smsmith 8338451Smsmith if (*argv == NULL) { 8438451Smsmith (void)printf("is %s\n", 8538451Smsmith sb.st_mode & S_IXUSR ? "y" : 8638451Smsmith sb.st_mode & S_IXGRP ? "b" : "n"); 8738451Smsmith return(sb.st_mode & (S_IXUSR | S_IXGRP) ? 0 : 1); 8838451Smsmith 8938451Smsmith } 9038451Smsmith 9138451Smsmith switch(argv[0][0]) { 9238451Smsmith case 'n': 9338451Smsmith if (chmod(name, sb.st_mode & ~(S_IXUSR | S_IXGRP)) < 0) 9438451Smsmith err(2, "%s", name); 9538451Smsmith break; 9638451Smsmith case 'y': 9738451Smsmith if (chmod(name, (sb.st_mode & ~(S_IXUSR | S_IXGRP)) | S_IXUSR) < 0) 9838451Smsmith err(2, "%s", name); 9938451Smsmith break; 10038451Smsmith case 'b': 10138451Smsmith if (chmod(name, (sb.st_mode & ~(S_IXUSR | S_IXGRP)) | S_IXGRP) < 0) 10238451Smsmith err(2, "%s", name); 10338451Smsmith break; 10438451Smsmith default: 10538451Smsmith usage(); 10638451Smsmith } 10738451Smsmith return(sb.st_mode & (S_IXUSR | S_IXGRP) ? 0 : 1); 10838451Smsmith} 109 110static void 111usage() 112{ 113 (void)fprintf(stderr, "usage: biff [n | y | b]\n"); 114 exit(2); 115} 116