| 79 | } |
| 80 | |
| 81 | int |
| 82 | main (int argc, char **argv) |
| 83 | { |
| 84 | int optc; |
| 85 | |
| 86 | initialize_main (&argc, &argv); |
| 87 | set_program_name (argv[0]); |
| 88 | setlocale (LC_ALL, ""); |
| 89 | bindtextdomain (PACKAGE, LOCALEDIR); |
| 90 | textdomain (PACKAGE); |
| 91 | |
| 92 | initialize_exit_failure (TTY_WRITE_ERROR); |
| 93 | atexit (close_stdout); |
| 94 | |
| 95 | while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1) |
| 96 | { |
| 97 | switch (optc) |
| 98 | { |
| 99 | case 's': |
| 100 | silent = true; |
| 101 | break; |
| 102 | |
| 103 | case_GETOPT_HELP_CHAR; |
| 104 | |
| 105 | case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); |
| 106 | |
| 107 | default: |
| 108 | usage (TTY_USAGE); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (optind < argc) |
| 113 | { |
| 114 | error (0, 0, _("extra operand %s"), quote (argv[optind])); |
| 115 | usage (TTY_USAGE); |
| 116 | } |
| 117 | |
| 118 | if (silent) |
| 119 | return isatty (STDIN_FILENO) ? EXIT_SUCCESS : TTY_STDIN_NOTTY; |
| 120 | |
| 121 | int status; |
| 122 | char const *tty = ttyname (STDIN_FILENO); |
| 123 | |
| 124 | if (tty) |
| 125 | status = EXIT_SUCCESS; |
| 126 | else |
| 127 | { |
| 128 | int ttyname_err = errno; |
| 129 | if (isatty (STDIN_FILENO)) |
| 130 | error (TTY_TTYNAME_FAILURE, ttyname_err, _("ttyname error")); |
| 131 | tty = _("not a tty"); |
| 132 | status = TTY_STDIN_NOTTY; |
| 133 | } |
| 134 | |
| 135 | puts (tty); |
| 136 | return status; |
| 137 | } |
nothing calls this directly
no test coverage detected