OpenCoverage

tty.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/tty.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* tty -- print the name of the terminal connected to standard input-
2 Copyright (C) 1990-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Displays "not a tty" if stdin is not a terminal.-
18 Displays nothing if -s option is given.-
19 Exit status 0 if stdin is a tty, 1 if not a tty, 2 if usage error,-
20 3 if write error.-
21-
22 Written by David MacKenzie <djm@gnu.ai.mit.edu>. */-
23-
24#include <config.h>-
25#include <stdio.h>-
26#include <getopt.h>-
27#include <sys/types.h>-
28-
29#include "system.h"-
30#include "error.h"-
31#include "quote.h"-
32-
33/* Exit statuses. */-
34enum-
35 {-
36 TTY_STDIN_NOTTY = 1,-
37 TTY_FAILURE = 2,-
38 TTY_WRITE_ERROR = 3-
39 };-
40-
41/* The official name of this program (e.g., no 'g' prefix). */-
42#define PROGRAM_NAME "tty"-
43-
44#define AUTHORS proper_name ("David MacKenzie")-
45-
46/* If true, return an exit status but produce no output. */-
47static bool silent;-
48-
49static struct option const longopts[] =-
50{-
51 {"silent", no_argument, NULL, 's'},-
52 {"quiet", no_argument, NULL, 's'},-
53 {GETOPT_HELP_OPTION_DECL},-
54 {GETOPT_VERSION_OPTION_DECL},-
55 {NULL, 0, NULL, 0}-
56};-
57-
58void-
59usage (int status)-
60{-
61 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tty
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tty
5-6
62 emit_try_help ();
executed 5 times by 1 test: end of block
Executed by:
  • tty
5
63 else-
64 {-
65 printf (_("Usage: %s [OPTION]...\n"), program_name);-
66 fputs (_("\-
67Print the file name of the terminal connected to standard input.\n\-
68\n\-
69 -s, --silent, --quiet print nothing, only return an exit status\n\-
70"), stdout);-
71 fputs (HELP_OPTION_DESCRIPTION, stdout);-
72 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
73 emit_ancillary_info (PROGRAM_NAME);-
74 }
executed 6 times by 1 test: end of block
Executed by:
  • tty
6
75 exit (status);
executed 11 times by 1 test: exit (status);
Executed by:
  • tty
11
76}-
77-
78int-
79main (int argc, char **argv)-
80{-
81 int optc;-
82-
83 initialize_main (&argc, &argv);-
84 set_program_name (argv[0]);-
85 setlocale (LC_ALL, "");-
86 bindtextdomain (PACKAGE, LOCALEDIR);-
87 textdomain (PACKAGE);-
88-
89 initialize_exit_failure (TTY_WRITE_ERROR);-
90 atexit (close_stdout);-
91-
92 silent = false;-
93-
94 while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tty
FALSEevaluated 11 times by 1 test
Evaluated by:
  • tty
11-24
95 {-
96 switch (optc)-
97 {-
98 case 's':
executed 11 times by 1 test: case 's':
Executed by:
  • tty
11
99 silent = true;-
100 break;
executed 11 times by 1 test: break;
Executed by:
  • tty
11
101-
102 case_GETOPT_HELP_CHAR;
never executed: break;
executed 6 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • tty
0-6
103-
104 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • tty
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • tty
0-4
105-
106 default:
executed 3 times by 1 test: default:
Executed by:
  • tty
3
107 usage (TTY_FAILURE);-
108 }
never executed: end of block
0
109 }-
110-
111 if (optind < argc)
optind < argcDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tty
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tty
2-9
112 {-
113 error (0, 0, _("extra operand %s"), quote (argv[optind]));-
114 usage (TTY_FAILURE);-
115 }
never executed: end of block
0
116-
117 errno = ENOENT;-
118-
119 if (silent)
silentDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tty
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tty
2-7
120 return isatty (STDIN_FILENO) ? EXIT_SUCCESS : TTY_STDIN_NOTTY;
executed 7 times by 1 test: return isatty ( 0 ) ? 0 : TTY_STDIN_NOTTY;
Executed by:
  • tty
7
121-
122 int status = EXIT_SUCCESS;-
123 char const *tty = ttyname (STDIN_FILENO);-
124-
125 if (! tty)
! ttyDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tty
FALSEnever evaluated
0-2
126 {-
127 tty = _("not a tty");-
128 status = TTY_STDIN_NOTTY;-
129 }
executed 2 times by 1 test: end of block
Executed by:
  • tty
2
130-
131 puts (tty);-
132 return status;
executed 2 times by 1 test: return status;
Executed by:
  • tty
2
133}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2