summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-04 09:52:30 +0000
committertjr <tjr@FreeBSD.org>2002-06-04 09:52:30 +0000
commitf91c8f40be0986622f27dff87bd398261ee82d38 (patch)
tree492be9c005b52f2a0017cb8bb478acbc72f78a69 /usr.bin
parentf577e81d49fdd18efca5e4b8766665ed3535fc3f (diff)
downloadFreeBSD-src-f91c8f40be0986622f27dff87bd398261ee82d38.zip
FreeBSD-src-f91c8f40be0986622f27dff87bd398261ee82d38.tar.gz
Respect the setting of the COLUMNS environment variable, use it instead of
the TTY width obtained by ioctl() when set & non-null. (SUSv3)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/who/who.113
-rw-r--r--usr.bin/who/who.c22
2 files changed, 29 insertions, 6 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1
index d2d93f0..d84a24c 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 ccb775b..24f4aad 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);
}
OpenPOWER on IntegriCloud