From 357b9a24a96478b7bcaaea8633f8f6a519f8903c Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 21 Jun 2014 08:44:01 -0400 Subject: cache terminal size, add SIGWINCH handler to reset Refactoring getcols, yet again. We do the following: 1) Introduce a static global in src/pacman/util.c 2) getcols always prefers this cached value, but will derive it from the COLUMNS environment var, the characteristics of stdout, or a sane default (in that order). 3) Introduce a SIGWINCH signal handler to reset the cached value, meaning we only call ioctl when we don't know the value. On my machine, pacman -Syy goes from ~4300 ioctl calls to 3. --- src/pacman/callback.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pacman/callback.c') diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 9cde1de7..6be20eca 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -424,7 +424,7 @@ void cb_question(alpm_question_t *question) "The following package cannot be upgraded due to unresolvable dependencies:\n", "The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); - list_display(" ", namelist, getcols(fileno(stdout))); + list_display(" ", namelist, getcols()); printf("\n"); q->skip = noyes(_n( "Do you want to skip the above package for this upgrade?", @@ -494,7 +494,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, int len, wclen, wcwid, padwid; wchar_t *wcstr; - const unsigned short cols = getcols(fileno(stdout)); + const unsigned short cols = getcols(); if(config->noprogressbar || cols == 0) { return; @@ -664,7 +664,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) const char *rate_label, *xfered_label; int file_percent = 0, total_percent = 0; - const unsigned short cols = getcols(fileno(stdout)); + const unsigned short cols = getcols(); if(config->noprogressbar || cols == 0 || file_total == -1) { if(file_xfered == 0) { -- cgit v1.2.3-24-g4f1b