libbb: factor out code which queries screen width

function                                             old     new   delta
get_terminal_width                                     -      17     +17
stty_main                                           1196    1197      +1
pstree_main                                          321     319      -2
ls_main                                              735     731      -4
watch_main                                           232     225      -7
bb_progress_update                                   714     706      -8
ps_main                                              555     543     -12
run_applet_and_exit                                  708     695     -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46)            Total: -28 byte

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2015-10-23 01:44:22 +02:00
parent a960748748
commit 641caaec3d
9 changed files with 15 additions and 15 deletions

View File

@@ -623,7 +623,7 @@ static int busybox_main(char **argv)
output_width = 80;
if (ENABLE_FEATURE_AUTOWIDTH) {
/* Obtain the terminal width */
get_terminal_width_height(0, &output_width, NULL);
output_width = get_terminal_width(2);
}
dup2(1, 2);

View File

@@ -45,13 +45,6 @@ enum {
STALLTIME = 5
};
static unsigned int get_tty2_width(void)
{
unsigned width;
get_terminal_width_height(2, &width, NULL);
return width;
}
void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
{
#if ENABLE_UNICODE_SUPPORT
@@ -148,7 +141,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
unsigned ratio = 100 * beg_and_transferred / totalsize;
fprintf(stderr, "%4u%%", ratio);
barlength = get_tty2_width() - 49;
barlength = get_terminal_width(2) - 49;
if (barlength > 0) {
/* god bless gcc for variable arrays :) */
char buf[barlength + 1];

View File

@@ -270,6 +270,12 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh
*width = wh_helper(win.ws_col, 80, "COLUMNS", &err);
return err;
}
int FAST_FUNC get_terminal_width(int fd)
{
unsigned width;
get_terminal_width_height(fd, &width, NULL);
return width;
}
int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp)
{