Respect setting of the COLUMNS environment variable (SUSv3)

This commit is contained in:
Tim J. Robbins 2002-06-04 10:20:10 +00:00
parent a28edf9a4a
commit 4f18100d73
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97804
2 changed files with 14 additions and 1 deletions

View File

@ -506,6 +506,16 @@ wait channel (as a symbolic name)
.It xstat
exit or stop status (valid only for stopped or zombie process)
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm :
.Bl -tag -width ".Ev COLUMNS"
.It Ev COLUMNS
If set, specifies the user's preferred output width in column positions.
By default,
.Nm
attempts to automatically determine the terminal width.
.El
.Sh FILES
.Bl -tag -width /var/db/kvm_kernel.db -compact
.It Pa /dev/kmem

View File

@ -123,12 +123,15 @@ main(int argc, char *argv[])
uid_t *uids;
int all, ch, flag, i, _fmt, lineno, nentries, dropgid;
int prtheader, wflag, what, xflg, uid, nuids;
char *cols;
char errbuf[_POSIX2_LINE_MAX];
const char *nlistf, *memf;
(void) setlocale(LC_ALL, "");
if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0')
termwidth = atoi(cols);
else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) ||
ws.ws_col == 0)