index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2014-08-11 09:43:12 -0400 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2014-09-30 14:04:23 +1000 |
commit | dc339faf6ad0dc07ab33c9f5bbdeecad5a927b6b (patch) | |
tree | 71843ce92d38b646989c9bb91c1d78db94e1a1b3 | |
parent | 50296576d006d433fbfd4a6c57d5f95a942f7833 (diff) |
-rw-r--r-- | src/pacman/util.c | 24 |
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2671e54c..3f2ed83b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -46,7 +46,7 @@ #include "conf.h" #include "callback.h" -static int cached_columns = 0; +static int cached_columns = -1; struct table_cell_t { char *label; @@ -158,13 +158,17 @@ static int flush_term_input(int fd) void columns_cache_reset(void) { - cached_columns = 0; + cached_columns = -1; } static int getcols_fd(int fd) { int width = -1; + if(!isatty(fd)) { + return 0; + } + #if defined(TIOCGSIZE) struct ttysize win; if(ioctl(fd, TIOCGSIZE, &win) == 0) { @@ -187,22 +191,26 @@ static int getcols_fd(int fd) unsigned short getcols(void) { const char *e; - int c = 0; + int c = -1; - if(cached_columns > 0) { + if(cached_columns >= 0) { return cached_columns; } e = getenv("COLUMNS"); - if(e) { - c = strtol(e, NULL, 10); + if(e && *e) { + char *p = NULL; + c = strtol(e, &p, 10); + if(*p != '\0') { + c= -1; + } } - if(c <= 0) { + if(c < 0) { c = getcols_fd(STDOUT_FILENO); } - if(c <= 0) { + if(c < 0) { c = 80; } |