diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c
index 6f6442a..a3f6d50 100644
--- a/caca/driver_ncurses.c
+++ b/caca/driver_ncurses.c
@@ -35,6 +35,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#if defined HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
 #if defined HAVE_SIGNAL_H
 #   include <signal.h>
 #endif
@@ -44,8 +47,7 @@
 #if defined HAVE_LOCALE_H
 #   include <locale.h>
 #endif
-
-#ifndef TIOCGWINSZ
+#if defined HAVE_TERMIOS_H
 #   include <termios.h>
 #endif
 
diff --git a/configure.ac b/configure.ac
index 199d1b8..8ae0f7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,7 +75,7 @@ AC_ARG_ENABLE(plugins,
 AC_ARG_ENABLE(doc,
   [  --enable-doc            build documentation (needs doxygen and LaTeX)])
 
-AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h dlfcn.h)
+AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h dlfcn.h termios.h)
 AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons)
 AC_CHECK_FUNCS(usleep gettimeofday)