Commit 27a3b4d5205a5fb3e2101128edd6653bd0c92189

Salvatore Sanfilippo 2013-02-08T03:33:05

Merge pull request #31 from fperrad/buildroot fix getColumns() for Buildroot

diff --git a/README.markdown b/README.markdown
index d98107b..a58ac2b 100644
--- a/README.markdown
+++ b/README.markdown
@@ -35,6 +35,7 @@ The library is currently less than 1000 lines of code. In order to use it in you
  * Linux text only console ($TERM = linux)
  * Linux KDE terminal application ($TERM = xterm)
  * Linux xterm ($TERM = xterm)
+ * Linux Buildroot ($TERM = vt100)
  * Mac OS X iTerm ($TERM = xterm)
  * Mac OS X default Terminal.app ($TERM = xterm)
  * OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
diff --git a/linenoise.c b/linenoise.c
index c690477..c4e3118 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -206,7 +206,7 @@ static void disableRawMode(int fd) {
 static int getColumns(void) {
     struct winsize ws;
 
-    if (ioctl(1, TIOCGWINSZ, &ws) == -1) return 80;
+    if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) return 80;
     return ws.ws_col;
 }