aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-10-27 00:02:56 -0500
committerRob Landley <rob@landley.net>2013-10-27 00:02:56 -0500
commitc9cc530371a981eef37fab4be6d6669e27b7fa0d (patch)
tree00a707092ed5095b684f0267fdb0ff6b4f215773 /lib
parent85ac09b6fe3e076930463819fec238fc6127c9fe (diff)
downloadtoybox-c9cc530371a981eef37fab4be6d6669e27b7fa0d.tar.gz
Refactor terminal querying.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/lib.c b/lib/lib.c
index b3c53df8..fe18b3e1 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -485,29 +485,28 @@ void crc_init(unsigned int *crc_table, int little_endian)
// set *x=0 and *y=0 before calling to detect failure to set either, or
// x=80 y=25 to provide defaults
-void terminal_size(unsigned *x, unsigned *y)
+void terminal_size(unsigned *xx, unsigned *yy)
{
struct winsize ws;
- int i;
+ unsigned i, x = xx ? *xx : 0, y = yy ? *yy : 0;
+ char *s;
- //memset(&ws, 0, sizeof(ws));
for (i=0; i<3; i++) {
- if (ioctl(i, TIOCGWINSZ, &ws)) continue;
- if (x) *x = ws.ws_col;
- if (y) *y = ws.ws_row;
- }
- if (x) {
- char *s = getenv("COLUMNS");
+ memset(&ws, 0, sizeof(ws));
+ if (!ioctl(i, TIOCGWINSZ, &ws)) {
+ if (ws.ws_col) x = ws.ws_col;
+ if (ws.ws_row) y = ws.ws_row;
- i = s ? atoi(s) : 0;
- if (i>0) *x = i;
+ break;
+ }
}
- if (y) {
- char *s = getenv("ROWS");
+ s = getenv("COLUMNS");
+ if (s) sscanf(s, "%u", &x);
+ s = getenv("ROWS");
+ if (s) sscanf(s, "%u", &y);
- i = s ? atoi(s) : 0;
- if (i>0) *y = i;
- }
+ if (xx) *xx = x;
+ if (yy) *yy = y;
}
int yesno(char *prompt, int def)