aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-16 20:36:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-16 20:36:48 +0200
commit68e980545af6a8ffb2980f94a6edac4dd89940f3 (patch)
tree821d730e4fcbe52666d4f43ae34f81681c395a5a
parentb24e55da84093dd6bf6dff79627e32459c3da071 (diff)
downloadbusybox-68e980545af6a8ffb2980f94a6edac4dd89940f3.tar.gz
ttysize: if stdin is not tty, try stdout, then stderr
function old new delta ttysize_main 135 175 +40 packed_usage 31686 31672 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/ttysize.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/miscutils/ttysize.c b/miscutils/ttysize.c
index 135ce8535..cba65b148 100644
--- a/miscutils/ttysize.c
+++ b/miscutils/ttysize.c
@@ -25,7 +25,7 @@
//usage:#define ttysize_trivial_usage
//usage: "[w] [h]"
//usage:#define ttysize_full_usage "\n\n"
-//usage: "Print dimension(s) of stdin's terminal, on error return 80x25"
+//usage: "Print dimensions of stdin tty, or 80x24"
#include "libbb.h"
@@ -37,7 +37,10 @@ int ttysize_main(int argc UNUSED_PARAM, char **argv)
w = 80;
h = 24;
- if (!ioctl(0, TIOCGWINSZ, &wsz)) {
+ if (ioctl(0, TIOCGWINSZ, &wsz) == 0
+ || ioctl(1, TIOCGWINSZ, &wsz) == 0
+ || ioctl(2, TIOCGWINSZ, &wsz) == 0
+ ) {
w = wsz.ws_col;
h = wsz.ws_row;
}