diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-06-04 09:52:30 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-06-04 09:52:30 +0000 |
commit | 8358edb6c77b4f04ae3188a6858600cebb214c90 (patch) | |
tree | 492be9c005b52f2a0017cb8bb478acbc72f78a69 /usr.bin/who | |
parent | a51b574c46eaac6f8b97deb20dac355f376fb159 (diff) |
Respect the setting of the COLUMNS environment variable, use it instead of
the TTY width obtained by ioctl() when set & non-null. (SUSv3)
Notes
Notes:
svn path=/head/; revision=97800
Diffstat (limited to 'usr.bin/who')
-rw-r--r-- | usr.bin/who/who.1 | 13 | ||||
-rw-r--r-- | usr.bin/who/who.c | 22 |
2 files changed, 29 insertions, 6 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1 index d2d93f0244aa..d84a24c51a5c 100644 --- a/usr.bin/who/who.1 +++ b/usr.bin/who/who.1 @@ -118,6 +118,19 @@ or one of the special characters '|', '}' and '~'. Logouts produce an output line without any user name. For more information on the special characters, see .Xr utmp 5 . +.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. +This is used when the +.Fl q +option is specified to calculate how many user names to display per line. +By default, +.Nm +attempts to automatically determine the terminal width. +.El .Sh FILES .Bl -tag -width /var/log/wtmp.[0-6] -compact .It Pa /var/run/utmp diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c index ccb775b65442..24f4aad720f9 100644 --- a/usr.bin/who/who.c +++ b/usr.bin/who/who.c @@ -32,7 +32,9 @@ __FBSDID("$FreeBSD$"); #include <sys/stat.h> #include <err.h> +#include <errno.h> #include <langinfo.h> +#include <limits.h> #include <locale.h> #include <paths.h> #include <pwd.h> @@ -271,12 +273,20 @@ int ttywidth(void) { struct winsize ws; - int width; - + long width; + char *cols, *ep; + + if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') { + errno = 0; + width = strtol(cols, &ep, 10); + if (errno || width <= 0 || width > INT_MAX || ep == cols || + *ep != '\0') + warnx("invalid COLUMNS environment variable ignored"); + else + return ((int)cols); + } if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) - width = ws.ws_col; - else - width = 80; + return (ws.ws_col); - return (width); + return (80); } |