summaryrefslogtreecommitdiff
path: root/bin/ps/ps.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-06-05 07:29:21 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-06-05 07:29:21 +0000
commit1c9cd75908cee5925c6e2e14b185984ed70cb292 (patch)
tree38ee38465b1f75e75e6b1d6ecd3f1ee944a5b4bc /bin/ps/ps.c
parent31f4d5b52a1451d75979ee148509f40db39080a4 (diff)
Add support for COLUMNS env variable, inspired by FreeBSD but with a dash
of strtonum() from millert@ sprinkled on top. Also, we've always supported TZ for formatting dates, so say so. ok jmc@ millert@
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r--bin/ps/ps.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 608ddd78804..4456af835ce 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ps.c,v 1.60 2014/05/07 01:31:25 tedu Exp $ */
+/* $OpenBSD: ps.c,v 1.61 2014/06/05 07:29:20 guenther Exp $ */
/* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */
/*-
@@ -98,15 +98,24 @@ main(int argc, char *argv[])
uid_t uid;
int all, ch, flag, i, fmt, lineno, nentries;
int prtheader, showthreads, wflag, kflag, what, Uflag, xflg;
- char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
-
- if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
- ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
- ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) ||
- ws.ws_col == 0)
- termwidth = 79;
- else
- termwidth = ws.ws_col - 1;
+ char *nlistf, *memf, *swapf, *cols, errbuf[_POSIX2_LINE_MAX];
+
+ if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') {
+ const char *errstr;
+
+ termwidth = strtonum(cols, 1, INT_MAX, &errstr);
+ if (errstr != NULL)
+ warnx("COLUMNS: %s: %s", cols, errstr);
+ }
+ if (termwidth == 0) {
+ if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
+ ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
+ ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) ||
+ ws.ws_col == 0)
+ termwidth = 79;
+ else
+ termwidth = ws.ws_col - 1;
+ }
if (argc > 1)
argv[1] = kludge_oldps_options(argv[1]);