aboutsummaryrefslogtreecommitdiff
path: root/bin/ls
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-06-04 10:11:29 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-06-04 10:11:29 +0000
commita28edf9a4a68207a93b90a9ba71617467957e257 (patch)
tree143a21a2cc0ca32a52d1a6f8460f624d67663dde /bin/ls
parent30e9580ecae64bbc4450342fe67db0f6ab3eeb62 (diff)
downloadsrc-a28edf9a4a68207a93b90a9ba71617467957e257.tar.gz
src-a28edf9a4a68207a93b90a9ba71617467957e257.zip
Ignore empty COLUMNS environment variable. COLUMNS should take precedence
over TTY width found via ioctl() (SUSv3)
Notes
Notes: svn path=/head/; revision=97803
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/ls.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 9791f01ba805..496c980d7a6f 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 {