Commit 7b1eb3e7 authored by Jan-Benedict Glaw's avatar Jan-Benedict Glaw Committed by Linus Torvalds

[PATCH] mconf.c: Honor $LINES and $COLUMNS if TIOCGWINSZ failed

While reading code, I found this buglet.  If the TIOCGWINSZ fails,
mconf.c assumes 24/80 as screen size, without honoring the LINES and
COLUMNS environment variables.  This is the shorter and IMHO more
correct version.
Signed-off-by: default avatarJan-Benedict Glaw <jbglaw@lug-owl.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8b04e514
...@@ -87,7 +87,7 @@ static char filename[PATH_MAX+1] = ".config"; ...@@ -87,7 +87,7 @@ static char filename[PATH_MAX+1] = ".config";
static char *args[1024], **argptr = args; static char *args[1024], **argptr = args;
static int indent; static int indent;
static struct termios ios_org; static struct termios ios_org;
static int rows, cols; static int rows = 0, cols = 0;
static struct menu *current_menu; static struct menu *current_menu;
static int child_count; static int child_count;
static int do_resize; static int do_resize;
...@@ -113,26 +113,24 @@ static void init_wsize(void) ...@@ -113,26 +113,24 @@ static void init_wsize(void)
struct winsize ws; struct winsize ws;
char *env; char *env;
if (ioctl(1, TIOCGWINSZ, &ws) == -1) { if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
rows = 24;
cols = 80;
} else {
rows = ws.ws_row; rows = ws.ws_row;
cols = ws.ws_col; cols = ws.ws_col;
if (!rows) { }
env = getenv("LINES");
if (env) if (!rows) {
rows = atoi(env); env = getenv("LINES");
if (!rows) if (env)
rows = 24; rows = atoi(env);
} if (!rows)
if (!cols) { rows = 24;
env = getenv("COLUMNS"); }
if (env) if (!cols) {
cols = atoi(env); env = getenv("COLUMNS");
if (!cols) if (env)
cols = 80; cols = atoi(env);
} if (!cols)
cols = 80;
} }
if (rows < 19 || cols < 80) { if (rows < 19 || cols < 80) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment