Index: gcc/fortran/error.c
===================================================================
--- gcc/fortran/error.c	(revision 199475)
+++ gcc/fortran/error.c	(working copy)
@@ -30,6 +30,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "flags.h"
 #include "gfortran.h"
 
+#if !(defined (_WIN32) || defined (VMS) || defined (__vxworks) || \
+      defined (__Lynx__) || defined (__ANDROID__))
+/* UNIX-like systems */
+#include <sys/ioctl.h>
+#endif
+
+
 static int suppress_errors = 0;
 
 static int warnings_not_errors = 0; 
@@ -62,6 +69,11 @@ gfc_pop_suppress_errors (void)
 static int
 get_terminal_width (void)
 {
+#ifdef TIOCGWINSZ
+  struct winsize w;
+  ioctl(0, TIOCGWINSZ, &w);
+  return w.ws_col;
+#else
   const char *p = getenv ("COLUMNS");
   if (p)
     {
@@ -71,6 +83,7 @@ get_terminal_width (void)
     }
   /* Use a reasonable default.  */
   return 80;
+#endif
 }
 
 
