1/* tty - return terminal name */ 2 3/* See Makefile for compilation details. */ 4 5#include "config.h" 6 7#include <stdio.h> 8#include "builtins.h" 9#include "shell.h" 10#include "bashgetopt.h" 11 12extern char *ttyname (); 13 14tty_builtin (list) 15 WORD_LIST *list; 16{ 17 int opt, sflag; 18 char *t; 19 20 reset_internal_getopt (); 21 sflag = 0; 22 while ((opt = internal_getopt (list, "s")) != -1) 23 { 24 switch (opt) 25 { 26 case 's': 27 sflag = 1; 28 break; 29 default: 30 builtin_usage (); 31 return (EX_USAGE); 32 } 33 } 34 list = loptend; 35 36 t = ttyname (0); 37 if (sflag == 0) 38 puts (t ? t : "not a tty"); 39 return (t ? EXECUTION_SUCCESS : EXECUTION_FAILURE); 40} 41 42char *tty_doc[] = { 43 "tty writes the name of the terminal that is opened for standard", 44 "input to standard output. If the `-s' option is supplied, nothing", 45 "is written; the exit status determines whether or not the standard", 46 "input is connected to a tty.", 47 (char *)NULL 48}; 49 50/* The standard structure describing a builtin command. bash keeps an array 51 of these structures. */ 52struct builtin tty_struct = { 53 "tty", /* builtin name */ 54 tty_builtin, /* function implementing the builtin */ 55 BUILTIN_ENABLED, /* initial flags for builtin */ 56 tty_doc, /* array of long documentation strings. */ 57 "tty [-s]", /* usage synopsis; becomes short_doc */ 58 0 /* reserved for internal use */ 59}; 60