--- src/ministat.c~	2011-10-26 14:47:27.000000000 +0200
+++ src/ministat.c	2011-10-27 16:13:48.000000000 +0200
@@ -13,9 +13,70 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/ioctl.h>
 #include <sys/queue.h>
 
+#ifdef __MINGW32__
+
+/* Emulate `err'.  */
+
+#include <stdarg.h>
+#include <errno.h>
+
+void __attribute__((noreturn))
+err (int status, const char *format, ...)
+{
+  va_list ap;
+
+  fprintf (stderr, "ministat: ");
+  if (format)
+    {
+      va_start (ap, format);
+      vfprintf (stderr, format, ap);
+      va_end (ap);
+      fprintf (stderr, ": %s\n", strerror (errno));
+    }
+  else
+    fputs ("\n", stderr);
+  exit (status);
+}
+
+/* Emulate Posix `ioctl' for getting screen dimensions.  */
+
+#include <windows.h>
+
+struct winsize {
+  unsigned short ws_col;
+  unsigned short ws_row;
+};
+
+#define TIOCGWINSZ 1
+
+int
+ioctl (int fd, int what, struct winsize *ws)
+{
+  CONSOLE_SCREEN_BUFFER_INFO csbi;
+  int retval;
+  HANDLE hstdout = GetStdHandle (STD_OUTPUT_HANDLE);
+
+  if (what == TIOCGWINSZ
+      && fd == 1
+      && hstdout != INVALID_HANDLE_VALUE
+      && GetConsoleScreenBufferInfo (hstdout, &csbi))
+    {
+      ws->ws_col = csbi.srWindow.Right - csbi.srWindow.Left + 1 - 1;
+      ws->ws_row = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
+      retval = 0;
+    }
+  else
+    retval = -1;
+
+  return retval;
+}
+
+#else
+#include <sys/ioctl.h>
+#endif
+
 #define NSTUDENT 100
 #define NCONF 6
 double const studentpct[] = { 80, 90, 95, 98, 99, 99.5 };
