diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-08-04 17:41:19 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-08-04 17:41:19 +0200 |
commit | cc1c9ca6f8117a28adf73b83f39b8dc3ba05fca4 (patch) | |
tree | 080b5fbb129b46382c85e48846a3f216eb98f726 /miscutils/less.c | |
parent | 93696341672cb8e086a55ecdef4c5617675c1da2 (diff) | |
download | busybox-w32-cc1c9ca6f8117a28adf73b83f39b8dc3ba05fca4.tar.gz busybox-w32-cc1c9ca6f8117a28adf73b83f39b8dc3ba05fca4.tar.bz2 busybox-w32-cc1c9ca6f8117a28adf73b83f39b8dc3ba05fca4.zip |
less: support "less 1<>TTY"
function old new delta
less_main 2466 2507 +41
xmalloc_ttyname 46 42 -4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/less.c')
-rw-r--r-- | miscutils/less.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 5ce0a1203..60105f42b 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -1608,6 +1608,9 @@ static void sigwinch_handler(int sig UNUSED_PARAM) | |||
1608 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1608 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1609 | int less_main(int argc, char **argv) | 1609 | int less_main(int argc, char **argv) |
1610 | { | 1610 | { |
1611 | char *tty_name; | ||
1612 | int tty_fd; | ||
1613 | |||
1611 | INIT_G(); | 1614 | INIT_G(); |
1612 | 1615 | ||
1613 | /* TODO: -x: do not interpret backspace, -xx: tab also */ | 1616 | /* TODO: -x: do not interpret backspace, -xx: tab also */ |
@@ -1637,10 +1640,28 @@ int less_main(int argc, char **argv) | |||
1637 | if (option_mask32 & FLAG_TILDE) | 1640 | if (option_mask32 & FLAG_TILDE) |
1638 | empty_line_marker = ""; | 1641 | empty_line_marker = ""; |
1639 | 1642 | ||
1640 | kbd_fd = open(CURRENT_TTY, O_RDONLY); | 1643 | /* Some versions of less can survive w/o controlling tty, |
1641 | if (kbd_fd < 0) | 1644 | * try to do the same. This also allows to specify an alternative |
1642 | return bb_cat(argv); | 1645 | * tty via "less 1<>TTY". |
1643 | ndelay_on(kbd_fd); | 1646 | * We don't try to use STDOUT_FILENO directly, |
1647 | * since we want to set this fd to non-blocking mode, | ||
1648 | * and not bother with restoring it on exit. | ||
1649 | */ | ||
1650 | tty_name = xmalloc_ttyname(STDOUT_FILENO); | ||
1651 | if (tty_name) { | ||
1652 | tty_fd = open(tty_name, O_RDONLY); | ||
1653 | free(tty_name); | ||
1654 | if (tty_fd < 0) | ||
1655 | goto try_ctty; | ||
1656 | } else { | ||
1657 | /* Try controlling tty */ | ||
1658 | try_ctty: | ||
1659 | tty_fd = open(CURRENT_TTY, O_RDONLY); | ||
1660 | if (tty_fd < 0) | ||
1661 | return bb_cat(argv); | ||
1662 | } | ||
1663 | ndelay_on(tty_fd); | ||
1664 | kbd_fd = tty_fd; /* save in a global */ | ||
1644 | 1665 | ||
1645 | tcgetattr(kbd_fd, &term_orig); | 1666 | tcgetattr(kbd_fd, &term_orig); |
1646 | term_less = term_orig; | 1667 | term_less = term_orig; |