1*b828b0feSThomas Cort /* $NetBSD: tty.c,v 1.8 2011/09/06 18:34:57 joerg Exp $ */
2*b828b0feSThomas Cort
3*b828b0feSThomas Cort /*
4*b828b0feSThomas Cort * Copyright (c) 1988, 1993
5*b828b0feSThomas Cort * The Regents of the University of California. All rights reserved.
6*b828b0feSThomas Cort *
7*b828b0feSThomas Cort * Redistribution and use in source and binary forms, with or without
8*b828b0feSThomas Cort * modification, are permitted provided that the following conditions
9*b828b0feSThomas Cort * are met:
10*b828b0feSThomas Cort * 1. Redistributions of source code must retain the above copyright
11*b828b0feSThomas Cort * notice, this list of conditions and the following disclaimer.
12*b828b0feSThomas Cort * 2. Redistributions in binary form must reproduce the above copyright
13*b828b0feSThomas Cort * notice, this list of conditions and the following disclaimer in the
14*b828b0feSThomas Cort * documentation and/or other materials provided with the distribution.
15*b828b0feSThomas Cort * 3. Neither the name of the University nor the names of its contributors
16*b828b0feSThomas Cort * may be used to endorse or promote products derived from this software
17*b828b0feSThomas Cort * without specific prior written permission.
18*b828b0feSThomas Cort *
19*b828b0feSThomas Cort * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*b828b0feSThomas Cort * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*b828b0feSThomas Cort * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*b828b0feSThomas Cort * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*b828b0feSThomas Cort * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*b828b0feSThomas Cort * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*b828b0feSThomas Cort * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*b828b0feSThomas Cort * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*b828b0feSThomas Cort * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*b828b0feSThomas Cort * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*b828b0feSThomas Cort * SUCH DAMAGE.
30*b828b0feSThomas Cort */
31*b828b0feSThomas Cort
32*b828b0feSThomas Cort #include <sys/cdefs.h>
33*b828b0feSThomas Cort #ifndef lint
34*b828b0feSThomas Cort __COPYRIGHT("@(#) Copyright (c) 1988, 1993\
35*b828b0feSThomas Cort The Regents of the University of California. All rights reserved.");
36*b828b0feSThomas Cort #endif /* not lint */
37*b828b0feSThomas Cort
38*b828b0feSThomas Cort #ifndef lint
39*b828b0feSThomas Cort #if 0
40*b828b0feSThomas Cort static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/6/93";
41*b828b0feSThomas Cort #endif
42*b828b0feSThomas Cort __RCSID("$NetBSD: tty.c,v 1.8 2011/09/06 18:34:57 joerg Exp $");
43*b828b0feSThomas Cort #endif /* not lint */
44*b828b0feSThomas Cort
45*b828b0feSThomas Cort #include <stdio.h>
46*b828b0feSThomas Cort #include <stdlib.h>
47*b828b0feSThomas Cort #include <unistd.h>
48*b828b0feSThomas Cort
49*b828b0feSThomas Cort __dead static void usage(void);
50*b828b0feSThomas Cort
51*b828b0feSThomas Cort int
main(int argc,char ** argv)52*b828b0feSThomas Cort main(int argc, char **argv)
53*b828b0feSThomas Cort {
54*b828b0feSThomas Cort int ch, sflag;
55*b828b0feSThomas Cort char *t;
56*b828b0feSThomas Cort
57*b828b0feSThomas Cort sflag = 0;
58*b828b0feSThomas Cort while ((ch = getopt(argc, argv, "s")) != -1) {
59*b828b0feSThomas Cort switch((char)ch) {
60*b828b0feSThomas Cort case 's':
61*b828b0feSThomas Cort sflag = 1;
62*b828b0feSThomas Cort break;
63*b828b0feSThomas Cort case '?':
64*b828b0feSThomas Cort default:
65*b828b0feSThomas Cort usage();
66*b828b0feSThomas Cort /* NOTREACHED */
67*b828b0feSThomas Cort }
68*b828b0feSThomas Cort }
69*b828b0feSThomas Cort
70*b828b0feSThomas Cort t = ttyname(STDIN_FILENO);
71*b828b0feSThomas Cort if (!sflag)
72*b828b0feSThomas Cort puts(t ? t : "not a tty");
73*b828b0feSThomas Cort exit(t ? 0 : 1);
74*b828b0feSThomas Cort }
75*b828b0feSThomas Cort
76*b828b0feSThomas Cort static void
usage(void)77*b828b0feSThomas Cort usage(void)
78*b828b0feSThomas Cort {
79*b828b0feSThomas Cort fprintf(stderr, "usage: tty [-s]\n");
80*b828b0feSThomas Cort exit(2);
81*b828b0feSThomas Cort }
82