diff options
author | Rob Landley <rob@landley.net> | 2005-09-01 02:57:45 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-01 02:57:45 +0000 |
commit | e0537f6194cf37651c6e7ac3033226f09dab7557 (patch) | |
tree | 38d91900ec491f8ad099c0e057efe88de0937336 | |
parent | 37adefc670eb9c0a8989d1b8a982e00644c566ee (diff) | |
download | busybox-w32-e0537f6194cf37651c6e7ac3033226f09dab7557.tar.gz busybox-w32-e0537f6194cf37651c6e7ac3033226f09dab7557.tar.bz2 busybox-w32-e0537f6194cf37651c6e7ac3033226f09dab7557.zip |
Bernhard Fischer suggested that get_terminal_width_height() should return
the result of the ioctl so callers can tell if we have a tty. (0 means
we have a tty, nonzero means the ioctl couldn't find size info and we
fake 80x24. Really we should fake 80x25, but oh well...)
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/get_terminal_width_height.c | 29 |
2 files changed, 8 insertions, 23 deletions
diff --git a/include/libbb.h b/include/libbb.h index 14670f026..077b310b6 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -474,7 +474,7 @@ extern void print_login_prompt(void); | |||
474 | 474 | ||
475 | extern void vfork_daemon_rexec(int nochdir, int noclose, | 475 | extern void vfork_daemon_rexec(int nochdir, int noclose, |
476 | int argc, char **argv, char *foreground_opt); | 476 | int argc, char **argv, char *foreground_opt); |
477 | extern void get_terminal_width_height(int fd, int *width, int *height); | 477 | extern int get_terminal_width_height(int fd, int *width, int *height); |
478 | extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)); | 478 | extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)); |
479 | extern void xregcomp(regex_t *preg, const char *regex, int cflags); | 479 | extern void xregcomp(regex_t *preg, const char *regex, int cflags); |
480 | 480 | ||
diff --git a/libbb/get_terminal_width_height.c b/libbb/get_terminal_width_height.c index 7a1af6dc1..ce3e83c0c 100644 --- a/libbb/get_terminal_width_height.c +++ b/libbb/get_terminal_width_height.c | |||
@@ -29,30 +29,15 @@ | |||
29 | #include "busybox.h" | 29 | #include "busybox.h" |
30 | 30 | ||
31 | /* It is perfectly ok to pass in a NULL for either width or for | 31 | /* It is perfectly ok to pass in a NULL for either width or for |
32 | * height, in which case that value will not be set. It is also | 32 | * height, in which case that value will not be set. */ |
33 | * perfectly ok to have CONFIG_FEATURE_AUTOWIDTH disabled, in | 33 | int get_terminal_width_height(int fd, int *width, int *height) |
34 | * which case you will always get 80x24 */ | ||
35 | void get_terminal_width_height(int fd, int *width, int *height) | ||
36 | { | 34 | { |
37 | struct winsize win = { 0, 0, 0, 0 }; | 35 | struct winsize win = { 0, 0, 0, 0 }; |
38 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 36 | int ret = ioctl(fd, TIOCGWINSZ, &win); |
39 | if (ioctl(fd, TIOCGWINSZ, &win) != 0) { | 37 | if (win.ws_row <= 1) win.ws_row = 24; |
40 | win.ws_row = 24; | 38 | if (win.ws_col <= 1) win.ws_col = 80; |
41 | win.ws_col = 80; | 39 | if (height) *height = (int) win.ws_row; |
42 | } | 40 | if (width) *width = (int) win.ws_col; |
43 | #endif | ||
44 | if (win.ws_row <= 1) { | ||
45 | win.ws_row = 24; | ||
46 | } | ||
47 | if (win.ws_col <= 1) { | ||
48 | win.ws_col = 80; | ||
49 | } | ||
50 | if (height) { | ||
51 | *height = (int) win.ws_row; | ||
52 | } | ||
53 | if (width) { | ||
54 | *width = (int) win.ws_col; | ||
55 | } | ||
56 | } | 41 | } |
57 | 42 | ||
58 | /* END CODE */ | 43 | /* END CODE */ |