Patch #1495999: Part two of Windows CE changes.
- update header checks, using autoconf
- provide dummies for getenv, environ, and GetVersion
- adjust MSC_VER check in socketmodule.c
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 5a81bfb..6d9776f 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -14,7 +14,11 @@
  */
 #ifdef MS_WINDOWS
 #include <windows.h>
+
+#ifdef HAVE_DIRECT_H
 #include <direct.h>    /* for getcwd() */
+#endif
+
 typedef __int64 hs_time;
 #define GETTIMEOFDAY(P_HS_TIME) \
 	{ LARGE_INTEGER _temp; \
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index c016cd7..abfca4e 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -16,7 +16,7 @@
 #include <string.h>
 #include <ctype.h>
 
-#ifndef DONT_HAVE_ERRNO_H
+#ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
 
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index eb6ceef..ba154ca 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -10,9 +10,9 @@
 #ifdef STDC_HEADERS
 #include <stddef.h>
 #else /* !STDC_HEADERS */
-#ifndef DONT_HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>		/* For size_t */
-#endif /* DONT_HAVE_SYS_TYPES_H */
+#endif /* HAVE_SYS_TYPES_H */
 #endif /* !STDC_HEADERS */
 
 struct arrayobject; /* Forward */
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 19970c9..b2dd675 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -50,7 +50,10 @@
 #endif /* UNIX */
 
 #include <string.h>
+
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
 
 /* Prefer MAP_ANONYMOUS since MAP_ANON is deprecated according to man page. */
 #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 12e1c83..6dcf1b0 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -64,14 +64,21 @@
 #include "osdefs.h"
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
+#endif /* HAVE_SYS_STAT_H */
 
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>		/* For WNOHANG */
 #endif
 
+#ifdef HAVE_SIGNAL_H
 #include <signal.h>
+#endif
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
@@ -246,9 +253,15 @@
 #endif
 
 #ifdef _MSC_VER
+#ifdef HAVE_DIRECT_H
 #include <direct.h>
+#endif
+#ifdef HAVE_IO_H
 #include <io.h>
+#endif
+#ifdef HAVE_PROCESS_H
 #include <process.h>
+#endif
 #include "osdefs.h"
 #define _WIN32_WINNT 0x0400	  /* Needed for CryptoAPI on some systems */
 #include <windows.h>
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index dfa4e85..ef67888 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -36,7 +36,7 @@
 extern void bzero(void *, int);
 #endif
 
-#ifndef DONT_HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 262abe8..2d3fc56 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -234,7 +234,9 @@
 #endif
 
 /* Generic includes */
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 
 /* Generic socket object definitions and includes */
 #define PySocket_BUILDING_SOCKET
@@ -270,7 +272,9 @@
 #else
 
 /* MS_WINDOWS includes */
-# include <fcntl.h>
+# ifdef HAVE_FCNTL_H
+#  include <fcntl.h>
+# endif
 
 #endif
 
@@ -290,7 +294,7 @@
    * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21,
    * for example, but not by 6.5.10.
    */
-#elif defined(_MSC_VER) && _MSC_VER>1200
+#elif defined(_MSC_VER) && _MSC_VER>1201
   /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and
    * EAI_* constants are defined in (the already included) ws2tcpip.h.
    */
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 87e543f..23de173 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -19,7 +19,9 @@
 
 #include <ctype.h>
 
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
 
 #ifdef QUICKWIN
 #include <io.h>