aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-20 22:06:01 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-20 22:06:01 +0000
commit181864668578d0e55d96cd48ae003aadd3f5a1f9 (patch)
treed75a76ec70963d1803d2a76bcf5030d30d8c6093 /libbb/xfuncs.c
parentc9d960a4afbb9dab6442c1a1d004a688d4553649 (diff)
downloadbusybox-w32-181864668578d0e55d96cd48ae003aadd3f5a1f9.tar.gz
busybox-w32-181864668578d0e55d96cd48ae003aadd3f5a1f9.tar.bz2
busybox-w32-181864668578d0e55d96cd48ae003aadd3f5a1f9.zip
Teach get_terminal_width_height to fall back to $LINES and $COLUMNS when
used via things like a serial console. git-svn-id: svn://busybox.net/trunk/busybox@16167 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d77bf3839..92091e555 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -6,7 +6,7 @@
6 * Copyright (C) 2006 Rob Landley 6 * Copyright (C) 2006 Rob Landley
7 * Copyright (C) 2006 Denis Vlasenko 7 * Copyright (C) 2006 Denis Vlasenko
8 * 8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 9 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
10 */ 10 */
11 11
12#include "busybox.h" 12#include "busybox.h"
@@ -494,3 +494,26 @@ void xstat(char *name, struct stat *stat_buf)
494} 494}
495#endif 495#endif
496 496
497#ifdef L_get_terminal_width_height
498/* It is perfectly ok to pass in a NULL for either width or for
499 * * height, in which case that value will not be set. */
500int get_terminal_width_height(int fd, int *width, int *height)
501{
502 struct winsize win = { 0, 0, 0, 0 };
503 int ret = ioctl(fd, TIOCGWINSZ, &win);
504 if (!win.ws_row) {
505 char *s = getenv("LINES");
506 if (s) win.ws_row = atoi(s);
507 }
508 if (win.ws_row <= 1) win.ws_row = 24;
509 if (!win.ws_col) {
510 char *s = getenv("COLUMNS");
511 if (s) win.ws_col = atoi(s);
512 }
513 if (win.ws_col <= 1) win.ws_col = 80;
514 if (height) *height = (int) win.ws_row;
515 if (width) *width = (int) win.ws_col;
516
517 return ret;
518}
519#endif