1 if standard input is a non-terminal file
2 if given incorrect arguments
3 if a write error occurs
-4 if standard input is closed or its type cannot be determined
@end display
/* Displays "not a tty" if stdin is not a terminal.
Displays nothing if -s option is given.
Exit status 0 if stdin is a tty, 1 if not a tty, 2 if usage error,
- 3 if write error, 4 for other stdin errors.
+ 3 if write error.
Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
{
TTY_STDIN_NOTTY = 1,
TTY_FAILURE = 2,
- TTY_WRITE_ERROR = 3,
- TTY_STDIN_ERROR = 4
+ TTY_WRITE_ERROR = 3
};
/* The official name of this program (e.g., no 'g' prefix). */
errno = ENOENT;
if (silent)
- return (isatty (STDIN_FILENO) ? EXIT_SUCCESS
- : (errno == ENOTTY || errno == EINVAL) ? TTY_STDIN_NOTTY
- : TTY_STDIN_ERROR);
+ return isatty (STDIN_FILENO) ? EXIT_SUCCESS : TTY_STDIN_NOTTY;
int status = EXIT_SUCCESS;
char const *tty = ttyname (STDIN_FILENO);
if (! tty)
{
- if (errno != ENOTTY && errno != EINVAL)
- error (TTY_STDIN_ERROR, errno, _("standard input"));
tty = _("not a tty");
status = TTY_STDIN_NOTTY;
}
returns_ 1 tty </dev/null || fail=1
returns_ 1 tty -s </dev/null || fail=1
+returns_ 1 tty <&- 2>/dev/null || fail=1
+returns_ 1 tty -s <&- || fail=1
returns_ 2 tty a || fail=1
returns_ 2 tty -s a || fail=1
returns_ 3 tty </dev/null >/dev/full || fail=1
fi
-returns_ 4 tty <&- 2>/dev/null || fail=1
-returns_ 4 tty -s <&- || fail=1
-
Exit $fail