[BusyBox] [patch] get_terminal_width_height() return value
Bernhard Fischer
rep.nop at aon.at
Tue Aug 23 21:55:47 UTC 2005
Hi,
attached patch makes libbb's get_terminal_width_height() return the
result of the ioctl. This is useful to check if the FD was e.g. a tty
(or not) etc.
I do not know if the preferred way of dealing with such a change is to
change get_terminal_width_height from void to int in general instead of
conditionally.
Please apply or let me know if you'd be willing to checkin a variant
which changes said function to return an int unconditionally.
Thank you,
Bernhard
-------------- next part --------------
diff -X excl -rduNp busybox.oorig/include/libbb.h busybox/include/libbb.h
--- busybox.oorig/include/libbb.h 2005-08-12 00:09:45.000000000 +0200
+++ busybox/include/libbb.h 2005-08-23 21:01:05.000000000 +0200
@@ -474,7 +474,11 @@ extern void print_login_prompt(void);
extern void vfork_daemon_rexec(int nochdir, int noclose,
int argc, char **argv, char *foreground_opt);
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+extern int get_terminal_width_height(int fd, int *width, int *height);
+#else
extern void get_terminal_width_height(int fd, int *width, int *height);
+#endif
extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *));
extern void xregcomp(regex_t *preg, const char *regex, int cflags);
diff -X excl -rduNp busybox.oorig/libbb/get_terminal_width_height.c busybox/libbb/get_terminal_width_height.c
--- busybox.oorig/libbb/get_terminal_width_height.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/get_terminal_width_height.c 2005-08-23 21:04:11.000000000 +0200
@@ -32,11 +32,16 @@
* height, in which case that value will not be set. It is also
* perfectly ok to have CONFIG_FEATURE_AUTOWIDTH disabled, in
* which case you will always get 80x24 */
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+int get_terminal_width_height(int fd, int *width, int *height)
+#else
void get_terminal_width_height(int fd, int *width, int *height)
+#endif
{
struct winsize win = { 0, 0, 0, 0 };
#ifdef CONFIG_FEATURE_AUTOWIDTH
- if (ioctl(fd, TIOCGWINSZ, &win) != 0) {
+ int ret = ioctl(fd, TIOCGWINSZ, &win);
+ if (ret) {
win.ws_row = 24;
win.ws_col = 80;
}
@@ -53,6 +58,9 @@ void get_terminal_width_height(int fd, i
if (width) {
*width = (int) win.ws_col;
}
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+ return ret;
+#endif
}
/* END CODE */
More information about the busybox
mailing list