diff options
author | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2016-03-17 05:27:11 +0000 |
---|---|---|
committer | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2016-03-17 05:27:11 +0000 |
commit | 8fcd372cac9eb2e1f5b77be5c644c16050a14ff5 (patch) | |
tree | 57ded33cc5e6839167ba569d1e58d6bb92f5bb85 /sbin/growfs/growfs.c | |
parent | 06ada816bc102f9194fd229056dd05d0a1c41409 (diff) |
Switch (non-curses, non-ksh) programs that use COLUMNS to a single idiom.
Previously behaviors were all over the map. This changes them to
use COLUMNS first, and either terminal width or a hardcoded value
(typically 80) as appropriate.
ok deraadt@; man bits ok jmc@
Diffstat (limited to 'sbin/growfs/growfs.c')
-rw-r--r-- | sbin/growfs/growfs.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 4a8c506184c..34c8d3b4162 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: growfs.c,v 1.49 2016/01/29 11:50:40 tb Exp $ */ +/* $OpenBSD: growfs.c,v 1.50 2016/03/17 05:27:10 bentley Exp $ */ /* * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz * Copyright (c) 1980, 1989, 1993 The Regents of the University of California. @@ -1666,15 +1666,13 @@ charsperline(void) struct winsize ws; columns = 0; - if (ioctl(0, TIOCGWINSZ, &ws) != -1) { - columns = ws.ws_col; - } - if (columns == 0 && (cp = getenv("COLUMNS"))) { + if ((cp = getenv("COLUMNS")) != NULL) columns = strtonum(cp, 1, INT_MAX, NULL); - } - if (columns == 0) { - columns = 80; /* last resort */ - } + if (columns == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 && + ws.ws_col > 0) + columns = ws.ws_col; + if (columns == 0) + columns = 80; return columns; } |