summaryrefslogtreecommitdiffstats
path: root/src/build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/build.cc')
-rw-r--r--src/build.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/build.cc b/src/build.cc
index 09c362a..ba7f1be 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -106,12 +106,14 @@ void BuildStatus::PrintStatus(Edge* edge) {
to_print = edge->EvaluateCommand();
if (smart_terminal_) {
- // Limit output to width of the terminal so we don't cause line-wrapping.
+ // Limit output to width of the terminal if provided so we don't cause
+ // line-wrapping.
winsize size;
- if (ioctl(0, TIOCGWINSZ, &size) == 0) {
+ if ((ioctl(0, TIOCGWINSZ, &size) == 0) && size.ws_col) {
const int kMargin = 15; // Space for [xxx/yyy] and "...".
if (to_print.size() + kMargin > size.ws_col) {
- int substr = to_print.size() + kMargin - size.ws_col;
+ int substr = std::min(to_print.size(),
+ to_print.size() + kMargin - size.ws_col);
to_print = "..." + to_print.substr(substr);
}
}