diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-08-31 15:49:35 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-08-31 15:49:35 +0000 |
commit | 27533efb8b0249f47a995f8afe1a24f8d301262c (patch) | |
tree | c9a80922386009fed5890823094329ef279eab51 | |
parent | d2a4baea36d7e707a34651f34a92fc8da7340eff (diff) |
calculate screen size way earlier, this will provide some opportunities
for taming the string manipulation in the later half of the program.
-rw-r--r-- | usr.bin/w/w.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index c15d5457abc..762566a7675 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -1,4 +1,4 @@ -/* $OpenBSD: w.c,v 1.58 2015/03/15 00:41:28 millert Exp $ */ +/* $OpenBSD: w.c,v 1.59 2015/08/31 15:49:34 deraadt Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -219,6 +219,17 @@ main(int argc, char *argv[]) kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(*kp), &nentries); if (kp == NULL) errx(1, "%s", kvm_geterr(kd)); + + if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) + ttywidth = 79; + else + ttywidth = ws.ws_col - 1; + argwidth = ttywidth - WUSED; + if (argwidth < 4) + argwidth = 8; + for (i = 0; i < nentries; i++, kp++) { if (kp->p_psflags & (PS_EMBRYO | PS_ZOMBIE)) continue; @@ -247,15 +258,6 @@ main(int argc, char *argv[]) } } } - if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && - ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && - ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) - ttywidth = 79; - else - ttywidth = ws.ws_col - 1; - argwidth = ttywidth - WUSED; - if (argwidth < 4) - argwidth = 8; /* sort by idle time */ if (sortidle && ehead != NULL) { struct entry *from = ehead, *save; |