diff options
| author | Pádraig Brady <P@draigBrady.com> | 2017-08-30 20:14:22 -0700 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2017-08-30 20:46:49 -0700 |
| commit | 173bee1bdffa53cd6c6f572fea46411eaec38b17 (patch) | |
| tree | 3d0fbf6f5897fae8348ff506e08e47740c84d7ee | |
| parent | tests: avoid printf '0*d' construct unsupported by ash (diff) | |
| download | coreutils-173bee1bdffa53cd6c6f572fea46411eaec38b17.tar.gz coreutils-173bee1bdffa53cd6c6f572fea46411eaec38b17.zip | |
tty: don't distinguish input errors
* src/tty.c (main): Don't distinguish ENOTTY from other errors,
because isatty() doesn't portably distinguish errors.
Solaris returns ENOENT for all input errors for example.
Musl also returns ENOENT, and ENODEV may be returned as disscussed at:
http://openwall.com/lists/musl/2017/04/06/6
* tests/misc/tty.sh: Adjust accordingly.
| -rw-r--r-- | doc/coreutils.texi | 1 | ||||
| -rw-r--r-- | src/tty.c | 11 | ||||
| -rwxr-xr-x | tests/misc/tty.sh | 5 |
3 files changed, 5 insertions, 12 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 5a0c47659..eb174620d 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -15123,7 +15123,6 @@ Exit status: 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 @@ -17,7 +17,7 @@ /* 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>. */ @@ -35,8 +35,7 @@ enum { 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). */ @@ -118,17 +117,13 @@ main (int argc, char **argv) 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; } diff --git a/tests/misc/tty.sh b/tests/misc/tty.sh index 904b5d6a2..aa3203be5 100755 --- a/tests/misc/tty.sh +++ b/tests/misc/tty.sh @@ -27,6 +27,8 @@ fi 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 @@ -38,7 +40,4 @@ if test -w /dev/full && test -c /dev/full; then 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 |
