tty.c revision 97482
140496Sbde/* 250473Speter * Copyright (c) 1988, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 918420Sbde * notice, this list of conditions and the following disclaimer. 101833Swollman * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 1233236Sjdp * documentation and/or other materials provided with the distribution. 1342029Sdfr * 3. All advertising materials mentioning features or use of this software 1442663Sjdp * must display the following acknowledgement: 1538960Sjdp * This product includes software developed by the University of 1634030Sdufault * California, Berkeley and its contributors. 1734326Sjb * 4. Neither the name of the University nor the names of its contributors 1826924Smsmith * may be used to endorse or promote products derived from this software 1944667Sphk * without specific prior written permission. 2036739Sphk * 217242Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 222573Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 232573Sbde * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2536890Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2617900Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2717900Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2817900Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2917900Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3026212Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3133298Sbde * SUCH DAMAGE. 3217900Speter */ 333329Sbde 3434030Sdufault#ifndef lint 3534030Sdufaultstatic const char copyright[] = 3634925Sdufault"@(#) Copyright (c) 1988, 1993\n\ 3734030Sdufault The Regents of the University of California. All rights reserved.\n"; 3834030Sdufault#endif /* not lint */ 3942774Sdt 401539Srgrimes#ifndef lint 4140496Sbde#if 0 4240496Sbdestatic char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/6/93"; 4317900Speter#endif 4423263Sbde#endif /* not lint */ 4539250Sgibbs 461539Srgrimes#include <sys/cdefs.h> 471539Srgrimes__FBSDID("$FreeBSD: head/usr.bin/tty/tty.c 97482 2002-05-29 17:08:09Z jmallett $"); 4826457Sjkh 4926457Sjkh#include <stdio.h> 5026457Sjkh#include <stdlib.h> 5126457Sjkh#include <unistd.h> 5226457Sjkh 531539Srgrimesstatic void usage(void); 5425734Speter 5525734Speterint 5636283Seivindmain(int argc, char *argv[]) 5736283Seivind{ 5825734Speter int ch, sflag; 5936283Seivind char *t; 6025734Speter 6125734Speter sflag = 0; 6225734Speter while ((ch = getopt(argc, argv, "s")) != -1) 6325734Speter switch((char)ch) { 6425734Speter case 's': 6529504Sbde sflag = 1; 6644937Sphk break; 6717900Speter case '?': 6817900Speter default: 6917900Speter usage(); 7017900Speter } 7117900Speter 7217900Speter t = ttyname(0); 7317900Speter if (!sflag) 7417900Speter puts(t ? t : "not a tty"); 7517900Speter exit(t ? 0 : 1); 7617992Sadam} 7717992Sadam 7817992Sadamstatic void 7932170Ssteveusage(void) 8032181Sjkh{ 8117900Speter fprintf(stderr, "usage: tty [-s]\n"); 8217900Speter exit(2); 8317900Speter} 8417900Speter