From 74de74358aeb10d5833adb6cd4b216ce41e8e385 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 27 Mar 2015 16:46:41 -0400 Subject: [PATCH] pkgman: fix problems pointed out by Jerome & Axel. --- src/bin/pkgman/PackageManager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index 799af30aaf..a0a7ef7386 100644 --- a/src/bin/pkgman/PackageManager.cpp +++ b/src/bin/pkgman/PackageManager.cpp @@ -195,10 +195,14 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName, "\xE2\x96\x88", }; - struct winsize w; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); - const int width = (w.ws_col > 77) - ? 70 : (w.ws_col - 7); // we need 70 chars for the bar + 7 for %. + int width = 70; + + struct winsize winSize; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize) == 0 + && winSize.ws_col < 77) { + // We need 7 characters for the percent display + width = windowSize.ws_col - 7; + } int position; int ipart = (int)(completionPercentage * width);