diff --git a/configure b/configure
index 17b86a327ee0fa1dcaf96ec125e91bbdd820f570..bbb4eaa125c27f36a0df3880376b61e291d8c7fb 100755
--- a/configure
+++ b/configure
@@ -11909,6 +11909,9 @@ done
 
 
 
+
+
+
 
 
 
@@ -11958,6 +11961,7 @@ for ac_header in \
 	sys/mount.h \
 	sys/msg.h \
 	sys/param.h \
+	sys/poll.h \
 	sys/ptrace.h \
 	sys/reg.h \
 	sys/shm.h \
@@ -11969,6 +11973,7 @@ for ac_header in \
 	sys/syscall.h \
 	sys/sysctl.h \
 	sys/time.h \
+	sys/times.h \
 	sys/user.h \
 	sys/v86.h \
 	sys/v86intr.h \
@@ -11979,6 +11984,7 @@ for ac_header in \
 	termios.h \
 	ucontext.h \
 	unistd.h \
+	utime.h \
 
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/configure.ac b/configure.ac
index cf686c836c68e6223e527fa4a7733478180c8854..a9db1214497f9044e9d30ffdc586aed1fda6a052 100644
--- a/configure.ac
+++ b/configure.ac
@@ -989,6 +989,7 @@ AC_CHECK_HEADERS(\
 	sys/mount.h \
 	sys/msg.h \
 	sys/param.h \
+	sys/poll.h \
 	sys/ptrace.h \
 	sys/reg.h \
 	sys/shm.h \
@@ -1000,6 +1001,7 @@ AC_CHECK_HEADERS(\
 	sys/syscall.h \
 	sys/sysctl.h \
 	sys/time.h \
+	sys/times.h \
 	sys/user.h \
 	sys/v86.h \
 	sys/v86intr.h \
@@ -1010,6 +1012,7 @@ AC_CHECK_HEADERS(\
 	termios.h \
 	ucontext.h \
 	unistd.h \
+	utime.h \
 )
 AC_HEADER_STAT()
 
diff --git a/dlls/kernel/comm.c b/dlls/kernel/comm.c
index ae3b2f1f029ddacfe82d8f878747b9db6e1a78e7..f990a2cae480a365e0cdcb35ef816f58005b9779 100644
--- a/dlls/kernel/comm.c
+++ b/dlls/kernel/comm.c
@@ -74,7 +74,9 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#include <sys/poll.h>
+#ifdef HAVE_SYS_POOL_H
+# include <sys/poll.h>
+#endif
 #ifdef HAVE_SYS_MODEM_H
 # include <sys/modem.h>
 #endif
@@ -2095,4 +2097,3 @@ BOOL WINAPI GetDefaultCommConfigW(
 	}
 	return ret;
 }
-
diff --git a/dlls/kernel/time.c b/dlls/kernel/time.c
index 01e0c07561ed72a5d803f6848f686d85bf48a36b..a4c5821aa6216a194d49d8c3cf7e13f8dc3d218a 100644
--- a/dlls/kernel/time.c
+++ b/dlls/kernel/time.c
@@ -28,7 +28,9 @@
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
-#include <sys/times.h>
+#ifdef HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
 #include "file.h"
 #include "ntddk.h"
 #include "winerror.h"
@@ -766,4 +768,3 @@ int WINAPI	SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWST
 	  Locale, Calendar, CalType, debugstr_w(lpCalData));
     return 0;
 }
-
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 38d2ec26c4856287292eddb72dea85e648255fad..963efed81dbacca7fb0a0613d417ff7aaa6bdd02 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -21,8 +21,12 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+
 #include <time.h>
-#include <sys/times.h>
+#ifdef HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
 
 #include "msvcrt.h"
 #include "msvcrt/sys/timeb.h"
diff --git a/dlls/ntdll/cdrom.c b/dlls/ntdll/cdrom.c
index ba59d589d1a23afb9b5e0ed6d47d4bfc424d6d11..223afcb19d13eeb572e430cf7d5908f70b6e681c 100644
--- a/dlls/ntdll/cdrom.c
+++ b/dlls/ntdll/cdrom.c
@@ -21,10 +21,14 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef HAVE_IO_H
+# include <io.h>
+#endif
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c
index 9cf808d2f38349e7ae57cb75849929ac02b64118..7a1497e4c461b99045ae8cfc62ef024f5f8d1b19 100644
--- a/dlls/ntdll/debugtools.c
+++ b/dlls/ntdll/debugtools.c
@@ -21,6 +21,9 @@
 #include "config.h"
 #include "wine/port.h"
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/dlls/ntdll/error.c b/dlls/ntdll/error.c
index ca958d03ccdfe536d94dac8daa1ea9a02e0d4970..2a5c7e837cf88b54fe2abf89aed6cd1c199a6401 100644
--- a/dlls/ntdll/error.c
+++ b/dlls/ntdll/error.c
@@ -32,7 +32,7 @@ struct error_table
     const WORD *table;
 };
 
-static const struct error_table error_table[];
+static const struct error_table error_table[12];
 
 /**************************************************************************
  *           RtlNtStatusToDosError (NTDLL.@)
diff --git a/dlls/ntdll/om.c b/dlls/ntdll/om.c
index be876c89be4311d554b724bfbbb40a1d048ab130..dbc3899ad9f5416475d2f433e9568978d7788ffe 100644
--- a/dlls/ntdll/om.c
+++ b/dlls/ntdll/om.c
@@ -22,6 +22,9 @@
 
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_IO_H
+# include <io.h>
+#endif
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
diff --git a/dlls/ntdll/sec.c b/dlls/ntdll/sec.c
index f97dd3874a5a2bd175d81aa63d5f2927f36c733c..614768a89354d7b99afbfc530d8203726d2eb6a3 100644
--- a/dlls/ntdll/sec.c
+++ b/dlls/ntdll/sec.c
@@ -745,8 +745,13 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString(
         NTSTATUS status;
         ANSI_STRING AnsiStr;
 
-        struct passwd *pwd = getpwuid( getuid() );
-        p = (pwd) ? pwd->pw_name : ".Default";
+#ifdef HAVE_GETPWUID
+	struct passwd *pwd = getpwuid( getuid() );
+	p = pwd ? pwd->pw_name : NULL;
+#else
+	p = getenv("USER");
+#endif
+	p = p ? p : ".Default";
 
 	FIXME("(%p %p %u)\n", String, Sid, AllocateString);
 
diff --git a/files/file.c b/files/file.c
index 64b78b31cf39920b2bb1e2a71601344ec1a3d9f3..f962cec769c95916b4fa40f4f73a040de56bbb41 100644
--- a/files/file.c
+++ b/files/file.c
@@ -44,12 +44,16 @@
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
-#include <sys/poll.h>
+#ifdef HAVE_SYS_POLL_H
+# include <sys/poll.h>
+#endif
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#include <utime.h>
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#endif
 
 #include "winerror.h"
 #include "windef.h"
diff --git a/files/smb.c b/files/smb.c
index b84096dff85dc056ef7c15b4cc1e2e735b0d6813..9624c5e43cd840ec5945939dbc563557bf2d6b1d 100644
--- a/files/smb.c
+++ b/files/smb.c
@@ -74,12 +74,16 @@
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
-#include <sys/poll.h>
+#ifdef HAVE_SYS_POLL_H
+# include <sys/poll.h>
+#endif
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#include <utime.h>
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
diff --git a/if1632/snoop.c b/if1632/snoop.c
index 2b16809b9c70d23c135ef1a5b3c993bd23e334ed..6a3108f4ef0ed4ba069347080aef13f057d6e43c 100644
--- a/if1632/snoop.c
+++ b/if1632/snoop.c
@@ -18,6 +18,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
diff --git a/include/config.h.in b/include/config.h.in
index 61c97ef6f9331bdb53b9a5bc59d86b1cba33a0a7..a0e545c0b995be74db4ed0588b323de94973ad92 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -497,6 +497,9 @@
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#undef HAVE_SYS_POLL_H
+
 /* Define to 1 if you have the <sys/ptrace.h> header file. */
 #undef HAVE_SYS_PTRACE_H
 
@@ -533,6 +536,9 @@
 /* Define to 1 if you have the <sys/sysctl.h> header file. */
 #undef HAVE_SYS_SYSCTL_H
 
+/* Define to 1 if you have the <sys/times.h> header file. */
+#undef HAVE_SYS_TIMES_H
+
 /* Define to 1 if you have the <sys/time.h> header file. */
 #undef HAVE_SYS_TIME_H
 
@@ -575,6 +581,9 @@
 /* Define to 1 if you have the `usleep' function. */
 #undef HAVE_USLEEP
 
+/* Define to 1 if you have the <utime.h> header file. */
+#undef HAVE_UTIME_H
+
 /* Define if we have va_copy */
 #undef HAVE_VA_COPY
 
diff --git a/misc/main.c b/misc/main.c
index 548eb6beba405373ca96d16625a6f755ca3eb2ca..3137a4366c0e96a8124a707dfc85327cecf20e81 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <locale.h>
 #include <ctype.h>
diff --git a/misc/version.c b/misc/version.c
index 0db79967c3dbb32c124e73b8fa7cc0d0d4941e0a..414c13cba7737475e8cb84fbdf7ca2fbf2aa94c1 100644
--- a/misc/version.c
+++ b/misc/version.c
@@ -21,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -401,7 +404,7 @@ static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
  * 5.12/5.00/5.00/4.00	Win98		calc
  * x.xx/5.00/5.00/4.00	win95/win98/NT4	IE5 files
  */
-DWORD VERSION_GetLinkedDllVersion(void)
+static DWORD VERSION_GetLinkedDllVersion(void)
 {
 	WINE_MODREF *wm;
 	DWORD WinVersion = NB_WINDOWS_VERSIONS;
@@ -1004,7 +1007,7 @@ void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
  *
  * returns TRUE if Win called with "/b" (bootlog.txt)
  */
-BOOL16 WINAPI DiagQuery16()
+BOOL16 WINAPI DiagQuery16(void)
 {
 	/* perhaps implement a Wine "/b" command line flag sometime ? */
 	return FALSE;
diff --git a/msdos/int1a.c b/msdos/int1a.c
index 262cba82508a00cc9d59524470d27e003652ea0b..f18d5ea1b48a5bc2f61fadedcddbc14b252f5425 100644
--- a/msdos/int1a.c
+++ b/msdos/int1a.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <time.h>
 #ifdef HAVE_SYS_TIME_H
diff --git a/msdos/int21.c b/msdos/int21.c
index c35128705da054c2ca8a349441cdde0e70395633..cf7b3f3e309f095b2285849d1d8f6819b0d58f17 100644
--- a/msdos/int21.c
+++ b/msdos/int21.c
@@ -40,7 +40,9 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#include <utime.h>
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#endif
 #include <ctype.h>
 #include "windef.h"
 #include "winbase.h"
@@ -2389,4 +2391,3 @@ FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
 	FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);
 	return NULL;
 }
-
diff --git a/scheduler/synchro.c b/scheduler/synchro.c
index f8b60fe574dc17c18e371f09a8bc743d85f0b780..bbf67525eda3985edbc35d23a94e46f6f51f52f9 100644
--- a/scheduler/synchro.c
+++ b/scheduler/synchro.c
@@ -26,7 +26,9 @@
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
-#include <sys/poll.h>
+#ifdef HAVE_SYS_POLL_H
+# include <sys/poll.h>
+#endif
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
diff --git a/win32/time.c b/win32/time.c
index cd700bb6c2d224f009e9e29997df91dacd0e42be..45798ec5a00ec5b01d0e13ea8410a080da6fadc5 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <string.h>
 #include <time.h>