Better support for configure detection of missing types, added check
for ssize_t.
Removed a couple of no longer used portability functions.
Various portability fixes in port.h.

diff --git a/configure b/configure
index 669a086..d76c3f1 100755
--- a/configure
+++ b/configure
@@ -5099,150 +5099,6 @@
 fi
 
 
-UTILLIBS=""
-
-
-for ac_func in openpty
-do
-as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_func" >&5
-echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
-if eval "test \"\${$as_ac_var+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
-#include "confdefs.h"
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $ac_func (); below.  */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char $ac_func ();
-char (*f) ();
-
-#ifdef F77_DUMMY_MAIN
-#  ifdef __cplusplus
-     extern "C"
-#  endif
-   int F77_DUMMY_MAIN() { return 1; }
-#endif
-int
-main ()
-{
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-f = $ac_func;
-#endif
-
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-         { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  eval "$as_ac_var=yes"
-else
-  echo "$as_me: failed program was:" >&5
-cat conftest.$ac_ext >&5
-eval "$as_ac_var=no"
-fi
-rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
-if test `eval echo '${'$as_ac_var'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
-
-else
-  echo "$as_me:$LINENO: checking for openpty in -lutil" >&5
-echo $ECHO_N "checking for openpty in -lutil... $ECHO_C" >&6
-if test "${ac_cv_lib_util_openpty+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lutil  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
-#include "confdefs.h"
-
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char openpty ();
-#ifdef F77_DUMMY_MAIN
-#  ifdef __cplusplus
-     extern "C"
-#  endif
-   int F77_DUMMY_MAIN() { return 1; }
-#endif
-int
-main ()
-{
-openpty ();
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-         { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_lib_util_openpty=yes
-else
-  echo "$as_me: failed program was:" >&5
-cat conftest.$ac_ext >&5
-ac_cv_lib_util_openpty=no
-fi
-rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_util_openpty" >&5
-echo "${ECHO_T}$ac_cv_lib_util_openpty" >&6
-if test $ac_cv_lib_util_openpty = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define HAVE_OPENPTY 1
-_ACEOF
-
-		UTILLIBS="-lutil"
-
-fi
-
-fi
-done
-
-
 DLLIBS=""
 
 echo "$as_me:$LINENO: checking for ANSI C header files" >&5
@@ -10431,7 +10287,6 @@
 
 
 
-
 for ac_func in \
 	__libc_fork \
 	_lwp_create \
@@ -10449,7 +10304,6 @@
 	getpagesize \
 	getprotobyname \
 	getprotobynumber \
-	getrlimit \
 	getservbyport \
 	getsockopt \
 	inet_network \
@@ -11139,15 +10993,13 @@
 echo "$as_me:$LINENO: result: $ac_cv_type_mode_t" >&5
 echo "${ECHO_T}$ac_cv_type_mode_t" >&6
 if test $ac_cv_type_mode_t = yes; then
-  :
-else
 
 cat >>confdefs.h <<_ACEOF
-#define mode_t int
+#define HAVE_MODE_T 1
 _ACEOF
 
-fi
 
+fi
 echo "$as_me:$LINENO: checking for off_t" >&5
 echo $ECHO_N "checking for off_t... $ECHO_C" >&6
 if test "${ac_cv_type_off_t+set}" = set; then
@@ -11197,15 +11049,13 @@
 echo "$as_me:$LINENO: result: $ac_cv_type_off_t" >&5
 echo "${ECHO_T}$ac_cv_type_off_t" >&6
 if test $ac_cv_type_off_t = yes; then
-  :
-else
 
 cat >>confdefs.h <<_ACEOF
-#define off_t long
+#define HAVE_OFF_T 1
 _ACEOF
 
-fi
 
+fi
 echo "$as_me:$LINENO: checking for pid_t" >&5
 echo $ECHO_N "checking for pid_t... $ECHO_C" >&6
 if test "${ac_cv_type_pid_t+set}" = set; then
@@ -11255,15 +11105,13 @@
 echo "$as_me:$LINENO: result: $ac_cv_type_pid_t" >&5
 echo "${ECHO_T}$ac_cv_type_pid_t" >&6
 if test $ac_cv_type_pid_t = yes; then
-  :
-else
 
 cat >>confdefs.h <<_ACEOF
-#define pid_t int
+#define HAVE_PID_T 1
 _ACEOF
 
-fi
 
+fi
 echo "$as_me:$LINENO: checking for size_t" >&5
 echo $ECHO_N "checking for size_t... $ECHO_C" >&6
 if test "${ac_cv_type_size_t+set}" = set; then
@@ -11313,13 +11161,68 @@
 echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
 echo "${ECHO_T}$ac_cv_type_size_t" >&6
 if test $ac_cv_type_size_t = yes; then
-  :
-else
 
 cat >>confdefs.h <<_ACEOF
-#define size_t unsigned
+#define HAVE_SIZE_T 1
 _ACEOF
 
+
+fi
+echo "$as_me:$LINENO: checking for ssize_t" >&5
+echo $ECHO_N "checking for ssize_t... $ECHO_C" >&6
+if test "${ac_cv_type_ssize_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+$ac_includes_default
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+if ((ssize_t *) 0)
+  return 0;
+if (sizeof (ssize_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_ssize_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_type_ssize_t=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_ssize_t" >&5
+echo "${ECHO_T}$ac_cv_type_ssize_t" >&6
+if test $ac_cv_type_ssize_t = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_SSIZE_T 1
+_ACEOF
+
+
 fi
 
 echo "$as_me:$LINENO: checking for long long" >&5
@@ -13261,7 +13164,6 @@
 s,@LINT@,$LINT,;t t
 s,@LINTFLAGS@,$LINTFLAGS,;t t
 s,@LDCOMBINE@,$LDCOMBINE,;t t
-s,@UTILLIBS@,$UTILLIBS,;t t
 s,@DLLIBS@,$DLLIBS,;t t
 s,@JPEGLIB@,$JPEGLIB,;t t
 s,@XLIB@,$XLIB,;t t
diff --git a/configure.ac b/configure.ac
index 04ea55b..7dac5fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,15 +95,6 @@
 dnl Check for -lmmap for OS/2
 AC_CHECK_LIB(mmap,mmap)
 
-dnl Check for openpty
-UTILLIBS=""
-AC_SUBST(UTILLIBS)
-AC_CHECK_FUNCS(openpty,,
-	[AC_CHECK_LIB(util,openpty,
-		[AC_DEFINE(HAVE_OPENPTY)
-		UTILLIBS="-lutil"]
-	)])
-
 DLLIBS=""
 AC_SUBST(DLLIBS)
 AC_CHECK_HEADERS(dlfcn.h,
@@ -880,7 +871,6 @@
 	getpagesize \
 	getprotobyname \
 	getprotobynumber \
-	getrlimit \
 	getservbyport \
 	getsockopt \
 	inet_network \
@@ -978,10 +968,7 @@
 
 AC_C_CONST
 AC_C_INLINE
-AC_TYPE_MODE_T
-AC_TYPE_OFF_T
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
+AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t])
 AC_CHECK_SIZEOF(long long,0)
 
 AC_CACHE_CHECK([whether linux/input.h is for real],
diff --git a/debugger/ext_debugger.c b/debugger/ext_debugger.c
index 636d16c..2379bc9 100644
--- a/debugger/ext_debugger.c
+++ b/debugger/ext_debugger.c
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
 
 #include <unistd.h>
 #include <errno.h>
diff --git a/debugger/memory.c b/debugger/memory.c
index f8bcf74..fc2f990 100644
--- a/debugger/memory.c
+++ b/debugger/memory.c
@@ -21,6 +21,8 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
+
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c
index 62d9e07..0104994 100644
--- a/dlls/advapi32/advapi.c
+++ b/dlls/advapi32/advapi.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 <errno.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/dlls/ddraw/ddraw/main.c b/dlls/ddraw/ddraw/main.c
index f6593df..3d61268 100644
--- a/dlls/ddraw/ddraw/main.c
+++ b/dlls/ddraw/ddraw/main.c
@@ -26,6 +26,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <string.h>
diff --git a/dlls/ddraw/helper.c b/dlls/ddraw/helper.c
index 15dfe42..0d3ee64 100644
--- a/dlls/ddraw/helper.c
+++ b/dlls/ddraw/helper.c
@@ -21,6 +21,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stddef.h>
 
diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c
index 5fe5886..b83c033 100644
--- a/dlls/dsound/dsound_main.c
+++ b/dlls/dsound/dsound_main.c
@@ -38,6 +38,8 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <stdio.h>
 #include <sys/types.h>
diff --git a/dlls/msvcrt/data.c b/dlls/msvcrt/data.c
index 256b0e9..390395f 100644
--- a/dlls/msvcrt/data.c
+++ b/dlls/msvcrt/data.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include <math.h>
 #include "msvcrt.h"
 
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index e8fa8d4..abb3052 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.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 <time.h>
 #include "ntddk.h"
 #include "wine/unicode.h"
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 16ae3e6..f293b91 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -20,6 +20,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include <time.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 0495183..134865d 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winnt.h"
 #include "winbase.h"
 #include "winuser.h"
diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c
index a6e82ae..b2b99c9 100644
--- a/dlls/ntdll/reg.c
+++ b/dlls/ntdll/reg.c
@@ -25,6 +25,9 @@
   *	HKEY_CLASSES		\\REGISTRY\\MACHINE\\SOFTWARE\\CLASSES
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include "wine/debug.h"
 #include "winreg.h"
diff --git a/dlls/odbc32/proxyodbc.c b/dlls/odbc32/proxyodbc.c
index 34380c9..4cf86ef 100644
--- a/dlls/odbc32/proxyodbc.c
+++ b/dlls/odbc32/proxyodbc.c
@@ -32,6 +32,7 @@
 
 #include "winbase.h"
 #include "wine/debug.h"
+#include "wine/library.h"
 
 #include "sql.h"
 #include "sqltypes.h"
diff --git a/dlls/quartz/iunk.c b/dlls/quartz/iunk.c
index 3e593d3..d0f4c0f 100644
--- a/dlls/quartz/iunk.c
+++ b/dlls/quartz/iunk.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include "windef.h"
 #include "winerror.h"
diff --git a/dlls/setupapi/parser.c b/dlls/setupapi/parser.c
index 68c10f5..e17be95 100644
--- a/dlls/setupapi/parser.c
+++ b/dlls/setupapi/parser.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 <limits.h>
 #include <string.h>
diff --git a/dlls/shdocvw/comimpl.c b/dlls/shdocvw/comimpl.c
index 65f73e7..ae5bedc 100644
--- a/dlls/shdocvw/comimpl.c
+++ b/dlls/shdocvw/comimpl.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include "windef.h"
 #include "winerror.h"
diff --git a/dlls/urlmon/comimpl.c b/dlls/urlmon/comimpl.c
index 4793dc2..9067a57 100644
--- a/dlls/urlmon/comimpl.c
+++ b/dlls/urlmon/comimpl.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include "windef.h"
 #include "winerror.h"
diff --git a/dlls/user/dde/misc.c b/dlls/user/dde/misc.c
index 551847f..fc2e84d 100644
--- a/dlls/user/dde/misc.c
+++ b/dlls/user/dde/misc.c
@@ -24,6 +24,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include <stdio.h>
 #include "winbase.h"
diff --git a/dlls/user/message.c b/dlls/user/message.c
index 6be340d..4b9b0ad 100644
--- a/dlls/user/message.c
+++ b/dlls/user/message.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 "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
diff --git a/dlls/user/text.c b/dlls/user/text.c
index e08abf0..b591ad8 100644
--- a/dlls/user/text.c
+++ b/dlls/user/text.c
@@ -24,6 +24,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include <assert.h>
 
diff --git a/dlls/winedos/module.c b/dlls/winedos/module.c
index 7c004de..f2d691f 100644
--- a/dlls/winedos/module.c
+++ b/dlls/winedos/module.c
@@ -21,6 +21,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 099f99a..195de9f 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -24,6 +24,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <errno.h>
 #include <stdio.h>
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index 8297a1b..93a5bd7 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -22,6 +22,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <X11/Xatom.h>
 
diff --git a/include/config.h.in b/include/config.h.in
index bee5c70..5f744ef 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -125,9 +125,6 @@
 /* Define to 1 if you have the `getprotobynumber' function. */
 #undef HAVE_GETPROTOBYNUMBER
 
-/* Define to 1 if you have the `getrlimit' function. */
-#undef HAVE_GETRLIMIT
-
 /* Define to 1 if you have the `getservbyport' function. */
 #undef HAVE_GETSERVBYPORT
 
@@ -275,6 +272,9 @@
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
+/* Define to 1 if the system has the type `mode_t'. */
+#undef HAVE_MODE_T
+
 /* Define if struct msghdr contains msg_accrights */
 #undef HAVE_MSGHDR_ACCRIGHTS
 
@@ -299,12 +299,12 @@
 /* Define to 1 if you have the <net/if.h> header file. */
 #undef HAVE_NET_IF_H
 
+/* Define to 1 if the system has the type `off_t'. */
+#undef HAVE_OFF_T
+
 /* Define if OpenGL is present on the system */
 #undef HAVE_OPENGL
 
-/* Define to 1 if you have the `openpty' function. */
-#undef HAVE_OPENPTY
-
 /* Define if you have the Open Sound system */
 #undef HAVE_OSS
 
@@ -314,6 +314,9 @@
 /* Define to 1 if you have the `pclose' function. */
 #undef HAVE_PCLOSE
 
+/* Define to 1 if the system has the type `pid_t'. */
+#undef HAVE_PID_T
+
 /* Define to 1 if you have the `popen' function. */
 #undef HAVE_POPEN
 
@@ -356,6 +359,9 @@
 /* Define to 1 if you have the `sigaltstack' function. */
 #undef HAVE_SIGALTSTACK
 
+/* Define to 1 if the system has the type `size_t'. */
+#undef HAVE_SIZE_T
+
 /* Define if struct sockaddr contains sa_len */
 #undef HAVE_SOCKADDR_SA_LEN
 
@@ -368,6 +374,9 @@
 /* Define to 1 if you have the <soundcard.h> header file. */
 #undef HAVE_SOUNDCARD_H
 
+/* Define to 1 if the system has the type `ssize_t'. */
+#undef HAVE_SSIZE_T
+
 /* Define to 1 if you have the `statfs' function. */
 #undef HAVE_STATFS
 
@@ -641,15 +650,3 @@
 /* Define as `__inline' if that's what the C compiler calls it, or to nothing
    if it is not supported. */
 #undef inline
-
-/* Define to `int' if <sys/types.h> does not define. */
-#undef mode_t
-
-/* Define to `long' if <sys/types.h> does not define. */
-#undef off_t
-
-/* Define to `int' if <sys/types.h> does not define. */
-#undef pid_t
-
-/* Define to `unsigned' if <sys/types.h> does not define. */
-#undef size_t
diff --git a/include/wine/library.h b/include/wine/library.h
index c047d13..2a288a2 100644
--- a/include/wine/library.h
+++ b/include/wine/library.h
@@ -28,6 +28,9 @@
 
 typedef void (*load_dll_callback_t)( void *, const char * );
 
+extern void *wine_dlopen( const char *filename, int flag, char *error, int errorsize );
+extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
+extern int wine_dlclose( void *handle, char *error, int errorsize );
 extern void wine_dll_set_callback( load_dll_callback_t load );
 extern void *wine_dll_load( const char *filename, char *error, int errorsize );
 extern void *wine_dll_load_main_exe( const char *name, int search_path,
diff --git a/include/wine/port.h b/include/wine/port.h
index 56d5d26..c161d22 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -21,9 +21,9 @@
 #ifndef __WINE_WINE_PORT_H
 #define __WINE_WINE_PORT_H
 
-#ifndef __WINE_CONFIG_H  
-# error You must include config.h to use this header  
-#endif  
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
 
 #define _GNU_SOURCE  /* for pread/pwrite */
 #include <fcntl.h>
@@ -40,18 +40,26 @@
 # include <unistd.h>
 #endif
 
-/* Types */
 
-#ifndef HAVE_GETRLIMIT
-#define RLIMIT_STACK 3
-typedef int rlim_t;
-struct rlimit
-{
-    rlim_t rlim_cur;
-    rlim_t rlim_max;
-};
-int getrlimit (int resource, struct rlimit *rlim);
-#endif /* HAVE_GETRLIMIT */
+/****************************************************************
+ * Type definitions
+ */
+
+#ifndef HAVE_MODE_T
+typedef int mode_t;
+#endif
+#ifndef HAVE_OFF_T
+typedef long off_t;
+#endif
+#ifndef HAVE_PID_T
+typedef int pid_t;
+#endif
+#ifndef HAVE_SIZE_T
+typedef unsigned int size_t;
+#endif
+#ifndef HAVE_SSIZE_T
+typedef int ssize_t;
+#endif
 
 #if !defined(HAVE_GETNETBYADDR) && !defined(HAVE_GETNETBYNAME)
 struct netent {
@@ -83,85 +91,18 @@
 # endif /* defined(__BEOS__) */
 #endif /* !defined(HAVE_STATFS) */
 
-/* Functions */
 
-#if !defined(HAVE_CLONE) && defined(linux)
-int clone(int (*fn)(void *arg), void *stack, int flags, void *arg);
-#endif /* !defined(HAVE_CLONE) && defined(linux) */
+/****************************************************************
+ * Macro definitions
+ */
 
-#ifndef HAVE_GETNETBYADDR
-struct netent *getnetbyaddr(unsigned long net, int type);
-#endif /* defined(HAVE_GETNETBYNAME) */
-
-#ifndef HAVE_GETNETBYNAME
-struct netent *getnetbyname(const char *name);
-#endif /* defined(HAVE_GETNETBYNAME) */
-
-#ifndef HAVE_GETPROTOBYNAME
-struct protoent *getprotobyname(const char *name);
-#endif /* !defined(HAVE_GETPROTOBYNAME) */
-
-#ifndef HAVE_GETPROTOBYNUMBER
-struct protoent *getprotobynumber(int proto);
-#endif /* !defined(HAVE_GETPROTOBYNUMBER) */
-
-#ifndef HAVE_GETSERVBYPORT
-struct servent *getservbyport(int port, const char *proto);
-#endif /* !defined(HAVE_GETSERVBYPORT) */
-
-#ifndef HAVE_GETSOCKOPT
-int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len);
-#endif /* !defined(HAVE_GETSOCKOPT) */
-
-#ifndef HAVE_MEMMOVE
-void *memmove(void *dest, const void *src, unsigned int len);
-#endif /* !defined(HAVE_MEMMOVE) */
-
-#ifndef HAVE_GETPAGESIZE
-size_t getpagesize(void);
-#endif  /* HAVE_GETPAGESIZE */
-
-#ifndef HAVE_INET_NETWORK
-unsigned long inet_network(const char *cp);
-#endif /* !defined(HAVE_INET_NETWORK) */
-
-#ifndef HAVE_STATFS
-int statfs(const char *name, struct statfs *info);
-#endif /* !defined(HAVE_STATFS) */
-
-#ifndef HAVE_STRNCASECMP
-# ifndef HAVE__STRNICMP
-int strncasecmp(const char *str1, const char *str2, size_t n);
-# else
-# define strncasecmp _strnicmp
-# endif
-#endif /* !defined(HAVE_STRNCASECMP) */
-
-#ifndef HAVE_OPENPTY
-struct termios;
-struct winsize;
-int openpty(int *master, int *slave, char *name, struct termios *term, struct winsize *winsize);
-#endif  /* HAVE_OPENPTY */
-
-#ifndef HAVE_STRERROR
-const char *strerror(int err);
-#endif /* !defined(HAVE_STRERROR) */
-
-#ifndef HAVE_STRCASECMP
-# ifndef HAVE__STRICMP
-int strcasecmp(const char *str1, const char *str2);
-# else
-# define strcasecmp _stricmp
-# endif
-#endif /* !defined(HAVE_STRCASECMP) */
-
-#ifndef HAVE_USLEEP
-int usleep (unsigned int useconds);
-#endif /* !defined(HAVE_USLEEP) */
-
-#ifndef HAVE_LSTAT
-int lstat(const char *file_name, struct stat *buf);
-#endif /* HAVE_LSTAT */
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#else
+#define RTLD_LAZY    0x001
+#define RTLD_NOW     0x002
+#define RTLD_GLOBAL  0x100
+#endif
 
 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
 #define popen _popen
@@ -171,16 +112,8 @@
 #define pclose _pclose
 #endif
 
-#ifndef HAVE_PREAD
-ssize_t pread( int fd, void *buf, size_t count, off_t offset );
-#endif /* HAVE_PREAD */
-
-#ifndef HAVE_PWRITE
-ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
-#endif /* HAVE_PWRITE */
-
 #ifndef S_ISLNK
-#define S_ISLNK(mod) (0)
+# define S_ISLNK(mod) (0)
 #endif /* S_ISLNK */
 
 /* So we open files in 64 bit access mode on Linux */
@@ -188,72 +121,6 @@
 # define O_LARGEFILE 0
 #endif
 
-extern void *wine_dlopen( const char *filename, int flag, char *error, int errorsize );
-extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
-extern int wine_dlclose( void *handle, char *error, int errorsize );
-
-#ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
-#else
-#define RTLD_LAZY	0x001
-#define RTLD_NOW	0x002
-#define RTLD_GLOBAL	0x100
-#endif
-
-/* Interlocked functions */
-
-#if defined(__i386__) && defined(__GNUC__)
-
-inline static long interlocked_cmpxchg( long *dest, long xchg, long compare )
-{
-    long ret;
-    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
-                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
-    return ret;
-}
-
-inline static void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
-{
-    void *ret;
-    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
-                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
-    return ret;
-}
-
-inline static long interlocked_xchg( long *dest, long val )
-{
-    long ret;
-    __asm__ __volatile__( "lock; xchgl %0,(%1)"
-                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
-    return ret;
-}
-
-inline static void *interlocked_xchg_ptr( void **dest, void *val )
-{
-    void *ret;
-    __asm__ __volatile__( "lock; xchgl %0,(%1)"
-                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
-    return ret;
-}
-
-inline static long interlocked_xchg_add( long *dest, long incr )
-{
-    long ret;
-    __asm__ __volatile__( "lock; xaddl %0,(%1)"
-                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
-    return ret;
-}
-
-#else  /* __i386___ && __GNUC__ */
-
-extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
-extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
-extern long interlocked_xchg( long *dest, long val );
-extern void *interlocked_xchg_ptr( void **dest, void *val );
-extern long interlocked_xchg_add( long *dest, long incr );
-
-#endif  /* __i386___ && __GNUC__ */
-
 /* Macros to define assembler functions somewhat portably */
 
 #ifdef NEED_UNDERSCORE_PREFIX
@@ -337,4 +204,170 @@
 #define GET_UA_DWORD(ptr)    GET_LE_DWORD(ptr)
 #endif
 
+
+/****************************************************************
+ * Function definitions (only when using libwine)
+ */
+
+#ifndef NO_LIBWINE
+
+#if !defined(HAVE_CLONE) && defined(linux)
+int clone(int (*fn)(void *arg), void *stack, int flags, void *arg);
+#endif /* !defined(HAVE_CLONE) && defined(linux) */
+
+#ifndef HAVE_GETNETBYADDR
+struct netent *getnetbyaddr(unsigned long net, int type);
+#endif /* defined(HAVE_GETNETBYNAME) */
+
+#ifndef HAVE_GETNETBYNAME
+struct netent *getnetbyname(const char *name);
+#endif /* defined(HAVE_GETNETBYNAME) */
+
+#ifndef HAVE_GETPAGESIZE
+size_t getpagesize(void);
+#endif  /* HAVE_GETPAGESIZE */
+
+#ifndef HAVE_GETPROTOBYNAME
+struct protoent *getprotobyname(const char *name);
+#endif /* !defined(HAVE_GETPROTOBYNAME) */
+
+#ifndef HAVE_GETPROTOBYNUMBER
+struct protoent *getprotobynumber(int proto);
+#endif /* !defined(HAVE_GETPROTOBYNUMBER) */
+
+#ifndef HAVE_GETSERVBYPORT
+struct servent *getservbyport(int port, const char *proto);
+#endif /* !defined(HAVE_GETSERVBYPORT) */
+
+#ifndef HAVE_GETSOCKOPT
+int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len);
+#endif /* !defined(HAVE_GETSOCKOPT) */
+
+#ifndef HAVE_INET_NETWORK
+unsigned long inet_network(const char *cp);
+#endif /* !defined(HAVE_INET_NETWORK) */
+
+#ifndef HAVE_LSTAT
+int lstat(const char *file_name, struct stat *buf);
+#endif /* HAVE_LSTAT */
+
+#ifndef HAVE_MEMMOVE
+void *memmove(void *dest, const void *src, unsigned int len);
+#endif /* !defined(HAVE_MEMMOVE) */
+
+#ifndef HAVE_PREAD
+ssize_t pread( int fd, void *buf, size_t count, off_t offset );
+#endif /* HAVE_PREAD */
+
+#ifndef HAVE_PWRITE
+ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
+#endif /* HAVE_PWRITE */
+
+#ifndef HAVE_STATFS
+int statfs(const char *name, struct statfs *info);
+#endif /* !defined(HAVE_STATFS) */
+
+#ifndef HAVE_STRNCASECMP
+# ifndef HAVE__STRNICMP
+int strncasecmp(const char *str1, const char *str2, size_t n);
+# else
+# define strncasecmp _strnicmp
+# endif
+#endif /* !defined(HAVE_STRNCASECMP) */
+
+#ifndef HAVE_STRERROR
+const char *strerror(int err);
+#endif /* !defined(HAVE_STRERROR) */
+
+#ifndef HAVE_STRCASECMP
+# ifndef HAVE__STRICMP
+int strcasecmp(const char *str1, const char *str2);
+# else
+# define strcasecmp _stricmp
+# endif
+#endif /* !defined(HAVE_STRCASECMP) */
+
+#ifndef HAVE_USLEEP
+int usleep (unsigned int useconds);
+#endif /* !defined(HAVE_USLEEP) */
+
+/* Interlocked functions */
+
+#if defined(__i386__) && defined(__GNUC__)
+
+inline static long interlocked_cmpxchg( long *dest, long xchg, long compare )
+{
+    long ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+inline static void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+inline static long interlocked_xchg( long *dest, long val )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+inline static void *interlocked_xchg_ptr( void **dest, void *val )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+inline static long interlocked_xchg_add( long *dest, long incr )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xaddl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
+    return ret;
+}
+
+#else  /* __i386___ && __GNUC__ */
+
+extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
+extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
+extern long interlocked_xchg( long *dest, long val );
+extern void *interlocked_xchg_ptr( void **dest, void *val );
+extern long interlocked_xchg_add( long *dest, long incr );
+
+#endif  /* __i386___ && __GNUC__ */
+
+#else /* NO_LIBWINE */
+
+#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
+
+#define clone             __WINE_NOT_PORTABLE(clone)
+#define getnetbyaddr      __WINE_NOT_PORTABLE(getnetbyaddr)
+#define getnetbyname      __WINE_NOT_PORTABLE(getnetbyname)
+#define getpagesize       __WINE_NOT_PORTABLE(getpagesize)
+#define getprotobyname    __WINE_NOT_PORTABLE(getprotobyname)
+#define getprotobynumber  __WINE_NOT_PORTABLE(getprotobynumber)
+#define getservbyport     __WINE_NOT_PORTABLE(getservbyport)
+#define getsockopt        __WINE_NOT_PORTABLE(getsockopt)
+#define inet_network      __WINE_NOT_PORTABLE(inet_network)
+#define lstat             __WINE_NOT_PORTABLE(lstat)
+#define memmove           __WINE_NOT_PORTABLE(memmove)
+#define pread             __WINE_NOT_PORTABLE(pread)
+#define pwrite            __WINE_NOT_PORTABLE(pwrite)
+#define statfs            __WINE_NOT_PORTABLE(statfs)
+#define strcasecmp        __WINE_NOT_PORTABLE(strcasecmp)
+#define strerror          __WINE_NOT_PORTABLE(strerror)
+#define strncasecmp       __WINE_NOT_PORTABLE(strncasecmp)
+#define usleep            __WINE_NOT_PORTABLE(usleep)
+
+#endif /* NO_LIBWINE */
+
 #endif /* !defined(__WINE_WINE_PORT_H) */
diff --git a/library/port.c b/library/port.c
index 64f8149..37e7dd9 100644
--- a/library/port.c
+++ b/library/port.c
@@ -210,56 +210,6 @@
 #endif /* HAVE_STRNCASECMP */
 
 /***********************************************************************
- *		openpty
- * NOTE
- *   It looks like the openpty that comes with glibc in RedHat 5.0
- *   is buggy (second call returns what looks like a dup of 0 and 1
- *   instead of a new pty), this is a generic replacement.
- *
- * FIXME
- *   We should have a autoconf check for this.
- */
-#ifndef HAVE_OPENPTY
-int openpty(int *master, int *slave, char *name, struct termios *term, struct winsize *winsize)
-{
-    const char *ptr1, *ptr2;
-    char pts_name[512];
-
-    strcpy (pts_name, "/dev/ptyXY");
-
-    for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
-        pts_name[8] = *ptr1;
-        for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
-            pts_name[9] = *ptr2;
-
-            if ((*master = open(pts_name, O_RDWR)) < 0) {
-                if (errno == ENOENT)
-                    return -1;
-                else
-                    continue;
-            }
-            pts_name[5] = 't';
-            if ((*slave = open(pts_name, O_RDWR)) < 0) {
-                pts_name[5] = 'p';
-		close (*master);
-                continue;
-            }
-
-            if (term != NULL)
-                tcsetattr(*slave, TCSANOW, term);
-            if (winsize != NULL)
-                ioctl(*slave, TIOCSWINSZ, winsize);
-            if (name != NULL)
-                strcpy(name, pts_name);
-            return *slave;
-        }
-    }
-    errno = EMFILE;
-    return -1;
-}
-#endif  /* HAVE_OPENPTY */
-
-/***********************************************************************
  *		getnetbyaddr
  */
 #ifndef HAVE_GETNETBYADDR
@@ -437,17 +387,6 @@
 #endif /* HAVE_PWRITE */
 
 
-/***********************************************************************
- *		getrlimit
- */
-#ifndef HAVE_GETRLIMIT
-int getrlimit (int resource, struct rlimit *rlim)
-{
-    return -1; /* FAIL */
-}
-#endif /* HAVE_GETRLIMIT */
-
-
 #if defined(__svr4__) || defined(__NetBSD__)
 /***********************************************************************
  *             try_mmap_fixed
diff --git a/misc/registry.c b/misc/registry.c
index fb9242b..49ef205 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -34,6 +34,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c
index 03203d6..5cc7cce 100644
--- a/objects/enhmetafile.c
+++ b/objects/enhmetafile.c
@@ -31,6 +31,9 @@
  *
  */ 
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include <assert.h>
 #include "winnls.h"
diff --git a/ole/ole2nls.c b/ole/ole2nls.c
index 213b5cb..a3320d7 100644
--- a/ole/ole2nls.c
+++ b/ole/ole2nls.c
@@ -20,6 +20,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 9669dab..ad580d0 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -20,6 +20,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <stdio.h>
 #include <windows.h>
 #include <winnt.h>
diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c
index 3ffe9de..8acc77a 100644
--- a/programs/wineconsole/wineconsole.c
+++ b/programs/wineconsole/wineconsole.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 <stdio.h>
 #include "wine/server.h"
 #include "wine/unicode.h"
diff --git a/scheduler/process.c b/scheduler/process.c
index 5dad535..037e226 100644
--- a/scheduler/process.c
+++ b/scheduler/process.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 <ctype.h>
 #include <errno.h>
diff --git a/scheduler/pthread.c b/scheduler/pthread.c
index 404f562..0dd7330 100644
--- a/scheduler/pthread.c
+++ b/scheduler/pthread.c
@@ -22,6 +22,8 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
+
 #define _GNU_SOURCE /* we may need to override some GNU extensions */
 
 #include <assert.h>
diff --git a/server/atom.c b/server/atom.c
index 90669cb..3ab8086 100644
--- a/server/atom.c
+++ b/server/atom.c
@@ -19,6 +19,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/server/console.c b/server/console.c
index d8b2a3c..5d94d73 100644
--- a/server/console.c
+++ b/server/console.c
@@ -21,6 +21,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <string.h>
diff --git a/server/debugger.c b/server/debugger.c
index be81e66..fa2c080 100644
--- a/server/debugger.c
+++ b/server/debugger.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 <signal.h>
 #include <string.h>
diff --git a/server/event.c b/server/event.c
index 08f9b88..3450933 100644
--- a/server/event.c
+++ b/server/event.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 <stdio.h>
 #include <stdlib.h>
diff --git a/server/handle.c b/server/handle.c
index a0e72b4..d419d59 100644
--- a/server/handle.c
+++ b/server/handle.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 <limits.h>
 #include <string.h>
diff --git a/server/mapping.c b/server/mapping.c
index 04eba65..73cc89c 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/server/mutex.c b/server/mutex.c
index 5b9ea21..28e838b 100644
--- a/server/mutex.c
+++ b/server/mutex.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 <stdio.h>
 #include <stdlib.h>
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 86c37aa..ecad8c1 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <fcntl.h>
diff --git a/server/object.c b/server/object.c
index eb6065a..2539e21 100644
--- a/server/object.c
+++ b/server/object.c
@@ -1,6 +1,5 @@
 /*
  * Server-side objects
- * These are the server equivalent of K32OBJ
  *
  * Copyright (C) 1998 Alexandre Julliard
  *
@@ -19,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 <limits.h>
 #include <stdlib.h>
diff --git a/server/process.c b/server/process.c
index 9b5dd50..55cd67e 100644
--- a/server/process.c
+++ b/server/process.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <errno.h>
diff --git a/server/queue.c b/server/queue.c
index 7ebef98..ae2486e 100644
--- a/server/queue.c
+++ b/server/queue.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 <stdio.h>
 #include <stdlib.h>
diff --git a/server/registry.c b/server/registry.c
index b2c5aa4..5ba94cc 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -24,6 +24,9 @@
  * - symbolic links
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
diff --git a/server/semaphore.c b/server/semaphore.c
index b8eb9b7..80f9626 100644
--- a/server/semaphore.c
+++ b/server/semaphore.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 <stdio.h>
 #include <stdlib.h>
diff --git a/server/snapshot.c b/server/snapshot.c
index f78f862..c9a1225 100644
--- a/server/snapshot.c
+++ b/server/snapshot.c
@@ -20,6 +20,9 @@
  * FIXME: heap snapshots not implemented
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/server/thread.c b/server/thread.c
index a43db32..47208f3 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <errno.h>
diff --git a/server/timer.c b/server/timer.c
index 0391d2f..523a797 100644
--- a/server/timer.c
+++ b/server/timer.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 <stdio.h>
 #include <stdlib.h>
diff --git a/server/trace.c b/server/trace.c
index b577e71..d957856 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <ctype.h>
 #include <stdio.h>
diff --git a/server/unicode.c b/server/unicode.c
index 17016b7..e8b577b 100644
--- a/server/unicode.c
+++ b/server/unicode.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 <ctype.h>
 #include <stdio.h>
 
diff --git a/server/window.c b/server/window.c
index 06ce0ec..b78baf5 100644
--- a/server/window.c
+++ b/server/window.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 "winbase.h"
diff --git a/tools/makedep.c b/tools/makedep.c
index 5a09e5e..18c3875 100644
--- a/tools/makedep.c
+++ b/tools/makedep.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 <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/tools/winedump/misc.c b/tools/winedump/misc.c
index aaac6e3..1039f42 100644
--- a/tools/winedump/misc.c
+++ b/tools/winedump/misc.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winedump.h"
 
 
diff --git a/tools/winedump/msmangle.c b/tools/winedump/msmangle.c
index 9264db4..283e0b2 100644
--- a/tools/winedump/msmangle.c
+++ b/tools/winedump/msmangle.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winedump.h"
 
 /* Type for parsing mangled types */
diff --git a/tools/winedump/output.c b/tools/winedump/output.c
index 2367d3c..ed860c9 100644
--- a/tools/winedump/output.c
+++ b/tools/winedump/output.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winedump.h"
 
 /* Output files */
diff --git a/tools/winedump/pe.c b/tools/winedump/pe.c
index 977cbe7..384ffab 100644
--- a/tools/winedump/pe.c
+++ b/tools/winedump/pe.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 <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/tools/winedump/search.c b/tools/winedump/search.c
index c817e7d..437f210 100644
--- a/tools/winedump/search.c
+++ b/tools/winedump/search.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winedump.h"
 
 static char *grep_buff = NULL;
diff --git a/tools/winedump/symbol.c b/tools/winedump/symbol.c
index 6aab652..0617003 100644
--- a/tools/winedump/symbol.c
+++ b/tools/winedump/symbol.c
@@ -17,6 +17,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#include "config.h"
+#include "wine/port.h"
+
 #include "winedump.h"
 
 
diff --git a/tools/wmc/utils.c b/tools/wmc/utils.c
index 3501073..e115c21 100644
--- a/tools/wmc/utils.c
+++ b/tools/wmc/utils.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/tools/wrc/readres.c b/tools/wrc/readres.c
index 4e29761..bb4605b 100644
--- a/tools/wrc/readres.c
+++ b/tools/wrc/readres.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c
index 372b9ee..a475e89 100644
--- a/tools/wrc/utils.c
+++ b/tools/wrc/utils.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/win32/console.c b/win32/console.c
index 6fb0c9b..274f71b 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -28,6 +28,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <stdio.h>
 #include <string.h>
diff --git a/win32/editline.c b/win32/editline.c
index ce67ffa..fd56de1 100644
--- a/win32/editline.c
+++ b/win32/editline.c
@@ -19,6 +19,8 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
+
 #include <string.h>
 
 #include "windef.h"
diff --git a/windows/win.c b/windows/win.c
index ddc9a9c..0b7acbc 100644
--- a/windows/win.c
+++ b/windows/win.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 <stdlib.h>
 #include <string.h>