diff options
author | tjr <tjr@FreeBSD.org> | 2002-06-04 09:52:30 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-06-04 09:52:30 +0000 |
commit | f91c8f40be0986622f27dff87bd398261ee82d38 (patch) | |
tree | 492be9c005b52f2a0017cb8bb478acbc72f78a69 /usr.bin/who/who.c | |
parent | f577e81d49fdd18efca5e4b8766665ed3535fc3f (diff) | |
download | FreeBSD-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/who/who.c')
-rw-r--r-- | usr.bin/who/who.c | 22 |
1 files changed, 16 insertions, 6 deletions
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); } |