xref: /titanic_51/usr/src/ucbcmd/biff/biff.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*
43  * biff
44  */
45 
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <stdio.h>
49 #include <locale.h>
50 
51 char	*ttyname();
52 
53 main(argc, argv)
54 	int argc;
55 	char **argv;
56 {
57 	char *cp = ttyname(2);
58 	struct stat stb;
59 
60 	(void) setlocale(LC_ALL, "");
61 
62 #if !defined(TEXT_DOMAIN)
63 #define TEXT_DOMAIN "SYS_TEST"
64 #endif
65 	(void) textdomain(TEXT_DOMAIN);
66 
67 	argc--, argv++;
68 	if (cp == 0)
69 		fprintf(stderr, gettext("biff failed:  cannot locate your tty:  ttyname() for file descriptor 2 returned NULL\n")), exit(1);
70 	if (stat(cp, &stb) < 0)
71 		perror(cp), exit(1);
72 	if (argc == 0) {
73 		printf("is %s\n", stb.st_mode&0100 ? gettext("y") : gettext("n"));
74 		exit((stb.st_mode&0100) ? 0 : 1);
75 	}
76 	switch (argv[0][0]) {
77 
78 	case 'y':
79 		if (chmod(cp, stb.st_mode|0100) < 0)
80 			perror(cp);
81 		break;
82 
83 	case 'n':
84 		if (chmod(cp, stb.st_mode&~0100) < 0)
85 			perror(cp);
86 		break;
87 
88 	default:
89 		fprintf(stderr, gettext("usage: biff [y] [n]\n"));
90 	}
91 	exit((stb.st_mode&0100) ? 0 : 1);
92 	/* NOTREACHED */
93 }
94 
95