diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-09 08:27:24 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-09 08:27:24 +0000 |
commit | f893da875a24138fac30f070c7101b5330f0fef0 (patch) | |
tree | ede441ba82f7a1bf9942ba33a64e91bcd8173920 | |
parent | 501bfe2630054f9988e08a5d77e1b1ff2abc78bb (diff) | |
download | busybox-w32-f893da875a24138fac30f070c7101b5330f0fef0.tar.gz busybox-w32-f893da875a24138fac30f070c7101b5330f0fef0.tar.bz2 busybox-w32-f893da875a24138fac30f070c7101b5330f0fef0.zip |
ls,ps,watch: measure terminal width on fd 0, not 1
-rw-r--r-- | coreutils/ls.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/xfuncs.c | 2 | ||||
-rw-r--r-- | procps/ps.c | 4 | ||||
-rw-r--r-- | procps/watch.c | 5 |
5 files changed, 9 insertions, 7 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index f47ec204c..920fad85e 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -811,7 +811,7 @@ int ls_main(int argc, char **argv) | |||
811 | 811 | ||
812 | #if ENABLE_FEATURE_AUTOWIDTH | 812 | #if ENABLE_FEATURE_AUTOWIDTH |
813 | /* Obtain the terminal width */ | 813 | /* Obtain the terminal width */ |
814 | get_terminal_width_height(STDOUT_FILENO, &terminal_width, NULL); | 814 | get_terminal_width_height(STDIN_FILENO, &terminal_width, NULL); |
815 | /* Go one less... */ | 815 | /* Go one less... */ |
816 | terminal_width--; | 816 | terminal_width--; |
817 | #endif | 817 | #endif |
diff --git a/include/libbb.h b/include/libbb.h index 546bbafc6..a14d6be44 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -803,7 +803,8 @@ extern int crypt_make_salt(char *p, int cnt, int rnd); | |||
803 | extern int update_passwd(const char *filename, const char *username, | 803 | extern int update_passwd(const char *filename, const char *username, |
804 | const char *new_pw); | 804 | const char *new_pw); |
805 | 805 | ||
806 | int get_terminal_width_height(const int fd, int *width, int *height); | 806 | /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ |
807 | int get_terminal_width_height(int fd, int *width, int *height); | ||
807 | 808 | ||
808 | int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); | 809 | int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
809 | void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); | 810 | void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 177247c6b..67c986640 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -612,7 +612,7 @@ void selinux_or_die(void) | |||
612 | 612 | ||
613 | /* It is perfectly ok to pass in a NULL for either width or for | 613 | /* It is perfectly ok to pass in a NULL for either width or for |
614 | * height, in which case that value will not be set. */ | 614 | * height, in which case that value will not be set. */ |
615 | int get_terminal_width_height(const int fd, int *width, int *height) | 615 | int get_terminal_width_height(int fd, int *width, int *height) |
616 | { | 616 | { |
617 | struct winsize win = { 0, 0, 0, 0 }; | 617 | struct winsize win = { 0, 0, 0, 0 }; |
618 | int ret = ioctl(fd, TIOCGWINSZ, &win); | 618 | int ret = ioctl(fd, TIOCGWINSZ, &win); |
diff --git a/procps/ps.c b/procps/ps.c index 50b6a6c94..5150a08a2 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -322,7 +322,7 @@ int ps_main(int argc, char **argv) | |||
322 | * and such large widths */ | 322 | * and such large widths */ |
323 | terminal_width = MAX_WIDTH; | 323 | terminal_width = MAX_WIDTH; |
324 | if (isatty(1)) { | 324 | if (isatty(1)) { |
325 | get_terminal_width_height(1, &terminal_width, NULL); | 325 | get_terminal_width_height(0, &terminal_width, NULL); |
326 | if (--terminal_width > MAX_WIDTH) | 326 | if (--terminal_width > MAX_WIDTH) |
327 | terminal_width = MAX_WIDTH; | 327 | terminal_width = MAX_WIDTH; |
328 | } | 328 | } |
@@ -364,7 +364,7 @@ int ps_main(int argc, char **argv) | |||
364 | if (w_count) { | 364 | if (w_count) { |
365 | terminal_width = (w_count==1) ? 132 : MAX_WIDTH; | 365 | terminal_width = (w_count==1) ? 132 : MAX_WIDTH; |
366 | } else { | 366 | } else { |
367 | get_terminal_width_height(1, &terminal_width, NULL); | 367 | get_terminal_width_height(0, &terminal_width, NULL); |
368 | /* Go one less... */ | 368 | /* Go one less... */ |
369 | if (--terminal_width > MAX_WIDTH) | 369 | if (--terminal_width > MAX_WIDTH) |
370 | terminal_width = MAX_WIDTH; | 370 | terminal_width = MAX_WIDTH; |
diff --git a/procps/watch.c b/procps/watch.c index 2ad0564cd..b2adcd5ce 100644 --- a/procps/watch.c +++ b/procps/watch.c | |||
@@ -28,7 +28,7 @@ int watch_main(int argc, char **argv) | |||
28 | { | 28 | { |
29 | unsigned opt; | 29 | unsigned opt; |
30 | unsigned period = 2; | 30 | unsigned period = 2; |
31 | unsigned cmdlen = 1; // 1 for terminal NUL | 31 | unsigned cmdlen; |
32 | char *header = NULL; | 32 | char *header = NULL; |
33 | char *cmd; | 33 | char *cmd; |
34 | char *tmp; | 34 | char *tmp; |
@@ -42,6 +42,7 @@ int watch_main(int argc, char **argv) | |||
42 | argv += optind; | 42 | argv += optind; |
43 | 43 | ||
44 | p = argv; | 44 | p = argv; |
45 | cmdlen = 1; // 1 for terminal NUL | ||
45 | while (*p) | 46 | while (*p) |
46 | cmdlen += strlen(*p++) + 1; | 47 | cmdlen += strlen(*p++) + 1; |
47 | tmp = cmd = xmalloc(cmdlen); | 48 | tmp = cmd = xmalloc(cmdlen); |
@@ -58,7 +59,7 @@ int watch_main(int argc, char **argv) | |||
58 | char *thyme; | 59 | char *thyme; |
59 | time_t t; | 60 | time_t t; |
60 | 61 | ||
61 | get_terminal_width_height(STDOUT_FILENO, &width, 0); | 62 | get_terminal_width_height(STDIN_FILENO, &width, 0); |
62 | header = xrealloc(header, width--); | 63 | header = xrealloc(header, width--); |
63 | // '%-*s' pads header with spaces to the full width | 64 | // '%-*s' pads header with spaces to the full width |
64 | snprintf(header, width, "Every %ds: %-*s", period, width, cmd); | 65 | snprintf(header, width, "Every %ds: %-*s", period, width, cmd); |