diff options
author | tjr <tjr@FreeBSD.org> | 2002-06-04 10:11:29 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-06-04 10:11:29 +0000 |
commit | c6efb66343b00c4a373073a02f93f09959f44c54 (patch) | |
tree | 143a21a2cc0ca32a52d1a6f8460f624d67663dde /bin/ls | |
parent | 096096d1a246973e0851929d3dc0dc8eb191299d (diff) | |
download | FreeBSD-src-c6efb66343b00c4a373073a02f93f09959f44c54.zip FreeBSD-src-c6efb66343b00c4a373073a02f93f09959f44c54.tar.gz |
Ignore empty COLUMNS environment variable. COLUMNS should take precedence
over TTY width found via ioctl() (SUSv3)
Diffstat (limited to 'bin/ls')
-rw-r--r-- | bin/ls/ls.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 9791f01..496c980 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -150,11 +150,11 @@ main(int argc, char *argv[]) /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1 || - !win.ws_col) { - if ((p = getenv("COLUMNS")) != NULL) - termwidth = atoi(p); - } else + termwidth = 80; + if ((p = getenv("COLUMNS")) != NULL && *p != '\0') + termwidth = atoi(p); + else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 && + win.ws_col > 0) termwidth = win.ws_col; f_nonprint = 1; } else { |