[BusyBox] [patch] auto width
Brian Pomerantz
bapper at piratehaven.org
Tue Mar 23 21:46:45 UTC 2004
I've noticed a bug in the "autowidth" feature more, and is probably in
others. The call to the function get_terminal_width_height() passes
in a file descriptor but that file descriptor is never used, instead
the ioctl() is called with 0. In more_main() the call to
get_terminal_width_height() passes 0 as the file descriptor instead of
fileno(cin). This isn't a problem when you more a file (e.g. "more
/etc/passwd") but when you pipe a file to it (e.g. "cat /etc/passwd |
more") the size of the terminal cannot be determined because file
descriptor 0 is not a terminal. The fix is simple, I've attached a
patch for more.c and get_terminal_width_height.c.
BAPper
-------------- next part --------------
Index: get_terminal_width_height.c
===================================================================
RCS file: /cvs/system/busybox/libbb/get_terminal_width_height.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 get_terminal_width_height.c
*** get_terminal_width_height.c 15 Jan 2004 12:12:20 -0000 1.1.1.1
--- get_terminal_width_height.c 23 Mar 2004 17:00:14 -0000
***************
*** 36,42 ****
{
struct winsize win = { 0, 0, 0, 0 };
#ifdef CONFIG_FEATURE_AUTOWIDTH
! if (ioctl(0, TIOCGWINSZ, &win) != 0) {
win.ws_row = 24;
win.ws_col = 80;
}
--- 36,42 ----
{
struct winsize win = { 0, 0, 0, 0 };
#ifdef CONFIG_FEATURE_AUTOWIDTH
! if (ioctl(fd, TIOCGWINSZ, &win) != 0) {
win.ws_row = 24;
win.ws_col = 80;
}
-------------- next part --------------
Index: more.c
===================================================================
RCS file: /cvs/system/busybox/util-linux/more.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 more.c
*** more.c 15 Jan 2004 12:12:21 -0000 1.1.1.1
--- more.c 23 Mar 2004 16:58:29 -0000
***************
*** 67,72 ****
--- 67,73 ----
int please_display_more_prompt = -1;
struct stat st;
FILE *file;
+ FILE *in_file = stdin;
int len, page_height;
argc--;
***************
*** 78,83 ****
--- 79,85 ----
cin = fopen(CURRENT_TTY, "r");
if (!cin)
cin = bb_xfopen(CONSOLE_DEV, "r");
+ in_file = cin;
please_display_more_prompt = 0;
#ifdef CONFIG_FEATURE_USE_TERMIOS
getTermSettings(fileno(cin), &initial_settings);
***************
*** 111,117 ****
if(please_display_more_prompt>0)
please_display_more_prompt = 0;
! get_terminal_width_height(0, &terminal_width, &terminal_height);
if (terminal_height > 4)
terminal_height -= 2;
if (terminal_width > 0)
--- 113,119 ----
if(please_display_more_prompt>0)
please_display_more_prompt = 0;
! get_terminal_width_height(fileno(in_file), &terminal_width, &terminal_height);
if (terminal_height > 4)
terminal_height -= 2;
if (terminal_width > 0)
More information about the busybox
mailing list