w: use COLUMNS environment if TIOCGWINSZ fails

A patch from Debian.

Backported-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Craig Small 2009-11-24 11:00:43 +11:00 committed by Craig Small
parent a0a51eb921
commit 88f485e20a

6
w.c
View File

@ -242,7 +242,7 @@ static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) {
/***** main */
int main(int argc, char **argv) {
char *user = NULL;
char *user = NULL, *p;
utmp_t *u;
struct winsize win;
int header=1, longform=1, from=1, args, maxcmd=80, ch;
@ -278,6 +278,10 @@ int main(int argc, char **argv) {
if (ioctl(1, TIOCGWINSZ, &win) != -1 && win.ws_col > 0)
maxcmd = win.ws_col;
else if (p = getenv("COLUMNS"))
maxcmd = atoi(p);
else
maxcmd = 80;
if (maxcmd < 71) {
fprintf(stderr, "%d column window is too narrow\n", maxcmd);
exit(1);