w: use COLUMNS environment if TIOCGWINSZ fails
A patch from Debian. Backported-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
a0a51eb921
commit
88f485e20a
6
w.c
6
w.c
@ -242,7 +242,7 @@ static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) {
|
|||||||
|
|
||||||
/***** main */
|
/***** main */
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *user = NULL;
|
char *user = NULL, *p;
|
||||||
utmp_t *u;
|
utmp_t *u;
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
int header=1, longform=1, from=1, args, maxcmd=80, ch;
|
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)
|
if (ioctl(1, TIOCGWINSZ, &win) != -1 && win.ws_col > 0)
|
||||||
maxcmd = win.ws_col;
|
maxcmd = win.ws_col;
|
||||||
|
else if (p = getenv("COLUMNS"))
|
||||||
|
maxcmd = atoi(p);
|
||||||
|
else
|
||||||
|
maxcmd = 80;
|
||||||
if (maxcmd < 71) {
|
if (maxcmd < 71) {
|
||||||
fprintf(stderr, "%d column window is too narrow\n", maxcmd);
|
fprintf(stderr, "%d column window is too narrow\n", maxcmd);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user