xref: /titanic_41/usr/src/cmd/tty/tty.c (revision 986fd29a0dc13f7608ef7f508f6e700bd7bc2720)
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 2004 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  * Type tty name
35  */
36 
37 #include <locale.h>
38 #include <stdio.h>
39 #include <unistd.h>
40 #include <sys/stermio.h>
41 
42 int
43 main(int argc, char **argv)
44 {
45 	char	*p;
46 	int	i;
47 	int	lflg	= 0;
48 	int	sflg	= 0;
49 
50 	(void) setlocale(LC_ALL, "");
51 #if !defined(TEXT_DOMAIN)
52 #define	TEXT_DOMAIN "SYS_TEST"
53 #endif
54 	(void) textdomain(TEXT_DOMAIN);
55 	while ((i = getopt(argc, argv, "ls")) != EOF)
56 		switch (i) {
57 		case 'l':
58 			lflg = 1;
59 			break;
60 		case 's':
61 			sflg = 1;
62 			break;
63 		case '?':
64 			(void) printf(gettext("Usage: tty [-l] [-s]\n"));
65 			return (2);
66 		}
67 	p = ttyname(0);
68 	if (!sflg)
69 		(void) printf("%s\n", (p? p: gettext("not a tty")));
70 	if (lflg) {
71 		if ((i = ioctl(0, STWLINE, 0)) == -1)
72 			(void) printf(gettext(
73 			    "not on an active synchronous line\n"));
74 		else
75 			(void) printf(gettext("synchronous line %d\n"), i);
76 	}
77 	return (p? 0: 1);
78 }
79