diff --git a/src/bin/pg_config/win32.mak b/src/bin/pg_config/win32.mak
index 77726a2dfce33f5ad378cebbe7375c164143bb6b..1a7597dfa9a7b46a3a2c79872e77b1f5fdf575bd 100644
--- a/src/bin/pg_config/win32.mak
+++ b/src/bin/pg_config/win32.mak
@@ -48,7 +48,7 @@ CLEAN :
 CPP_PROJ=/nologo $(OPT) /W3 /GX /D "WIN32" $(DEBUGDEF) /D "_CONSOLE" /D\
  "_MBCS" /Fp"$(INTDIR)\pg_config.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c \
  /I ..\..\include /I ..\..\interfaces\libpq /I ..\..\include\port\win32 \
- /D "HAVE_STRDUP" /D "FRONTEND"
+ /I ..\..\include\port\win32_msvc /D "HAVE_STRDUP" /D "FRONTEND"
 
 CPP_OBJS=$(INTDIR)/
 CPP_SBRS=.
@@ -63,6 +63,7 @@ LINK32_OBJS= \
 	"$(INTDIR)\pgstrcasecmp.obj" \
 	"$(OUTDIR)\path.obj" \
 	"$(INTDIR)\exec.obj" \
+	"$(INTDIR)\snprintf.obj" \
 !IFDEF DEBUG
 	"..\..\interfaces\libpq\Debug\libpqddll.lib"
 !ELSE
@@ -89,6 +90,11 @@ LINK32_OBJS= \
     $(CPP_PROJ) ..\..\port\exec.c
 <<
 
+"$(INTDIR)\snprintf.obj" : ..\..\port\snprintf.c
+    $(CPP) @<<
+    $(CPP_PROJ) ..\..\port\snprintf.c
+<<
+
 .c{$(CPP_OBJS)}.obj::
    $(CPP) @<<
    $(CPP_PROJ) $< 
diff --git a/src/bin/pg_dump/win32.mak b/src/bin/pg_dump/win32.mak
index 653fefe32c0d2a28bffaf6ca31e1477e58f8d0e9..f89e181fa2920510873b44df69fa89e494859d71 100644
--- a/src/bin/pg_dump/win32.mak
+++ b/src/bin/pg_dump/win32.mak
@@ -30,7 +30,8 @@ REFDOCDIR= ../../../doc/src/sgml/ref
 
 CPP_PROJ=/nologo $(OPT) /W3 /GX /D "WIN32" $(DEBUGDEF) /D "_CONSOLE" /D\
  "_MBCS" /Fp"$(INTDIR)\pg_dump.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c \
- /I ..\..\include /I ..\..\interfaces\libpq /I ..\..\include\port\win32 /I ..\..\backend \
+ /I ..\..\include /I ..\..\interfaces\libpq /I ..\..\include\port\win32 \
+ /I ..\..\include\port\win32_msvc /I ..\..\backend \
  /D "HAVE_STRDUP" /D "FRONTEND"
 
 CPP_OBJS=$(INTDIR)/
@@ -56,6 +57,7 @@ CLEAN :
 	-@erase "$(INTDIR)\path.obj"
 	-@erase "$(INTDIR)\pgstrcasecmp.obj"
 	-@erase "$(INTDIR)\sprompt.obj"
+	-@erase "$(INTDIR)\snprintf.obj"
 	-@erase "$(INTDIR)\pg_dump.pch"
 	-@erase "$(OUTDIR)\pg_dump.obj"
 	-@erase "$(OUTDIR)\pg_dump.exe"
@@ -92,7 +94,8 @@ LINK32_OBJS= \
 	"$(INTDIR)\getopt_long.obj" \
 	"$(INTDIR)\path.obj" \
 	"$(INTDIR)\pgstrcasecmp.obj" \
-	"$(INTDIR)\sprompt.obj"
+	"$(INTDIR)\sprompt.obj" \
+	"$(INTDIR)\snprintf.obj"
 
 LINK32_OBJS_DMP= \
 	"$(INTDIR)\common.obj" \
@@ -173,6 +176,11 @@ LINK32_OBJS	= $(LINK32_OBJS) "..\..\interfaces\libpq\Release\libpqdll.lib"
     $(CPP_PROJ) ..\..\port\sprompt.c
 <<
 
+"$(INTDIR)\snprintf.obj" : "$(INTDIR)" ..\..\port\snprintf.c
+    $(CPP) @<<
+    $(CPP_PROJ) ..\..\port\snprintf.c
+<<
+
 ..\..\backend\parser\parse.h : ..\..\backend\parser\gram.y
 	$(YACC) -y -d  ..\..\backend\parser\gram.y
 	$(MV) ..\..\backend\parser\y.tab.h ..\..\backend\parser\parse.h 
diff --git a/src/include/getaddrinfo.h b/src/include/getaddrinfo.h
index 6393ccfeae08b7362c6e0b8e125275da702f196c..ee60b71d840704949b9d96888d46c0cb5314fb05 100644
--- a/src/include/getaddrinfo.h
+++ b/src/include/getaddrinfo.h
@@ -15,7 +15,7 @@
  *
  * Copyright (c) 2003-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.20 2006/06/07 22:24:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.21 2006/07/06 02:12:32 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,7 +41,9 @@
 #define EAI_SYSTEM		(-11)
 #else							/* WIN32 */
 #ifdef WIN32_ONLY_COMPILER
+#ifndef WSA_NOT_ENOUGH_MEMORY
 #define WSA_NOT_ENOUGH_MEMORY   (WSAENOBUFS)
+#endif
 #define WSATYPE_NOT_FOUND       (WSABASEERR+109)
 #endif
 #define EAI_AGAIN		WSATRY_AGAIN
@@ -89,6 +91,7 @@
 
 #ifndef HAVE_STRUCT_ADDRINFO
 
+#ifndef WIN32
 struct addrinfo
 {
 	int			ai_flags;
@@ -100,6 +103,24 @@ struct addrinfo
 	char	   *ai_canonname;
 	struct addrinfo *ai_next;
 };
+#else
+/*
+ *	The order of the structure elements on Win32 doesn't match the
+ *	order specified in the standard, but we have to match it for
+ *	IPv6 to work.
+ */
+struct addrinfo
+{
+	int			ai_flags;
+	int			ai_family;
+	int			ai_socktype;
+	int			ai_protocol;
+	size_t		ai_addrlen;
+	char	   *ai_canonname;
+	struct sockaddr *ai_addr;
+	struct addrinfo *ai_next;
+};
+#endif
 #endif   /* HAVE_STRUCT_ADDRINFO */
 
 
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index b2cf29246ea451e483c4f6147b2d7ccabc948657..a805aa4da5c3f53bf447113a0b4d4dce312ef992 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -247,13 +247,17 @@
 
 /* Define to 1 if constants of type 'long long int' should have the suffix LL.
    */
+#if (_MSC_VER > 1200)
 #define HAVE_LL_CONSTANTS 1
+#endif
 
 /* Define to 1 if `long int' works and is 64 bits. */
 /* #undef HAVE_LONG_INT_64 */
 
 /* Define to 1 if `long long int' works and is 64 bits. */
+#if (_MSC_VER > 1200)
 #define HAVE_LONG_LONG_INT_64 
+#endif
 
 /* Define to 1 if you have the `memmove' function. */
 #define HAVE_MEMMOVE 1
@@ -395,7 +399,9 @@
 /* #undef HAVE_STRTOUQ */
 
 /* Define to 1 if the system has the type `struct addrinfo'. */
+#if (_MSC_VER > 1200)
 #define HAVE_STRUCT_ADDRINFO 1
+#endif
 
 /* Define to 1 if the system has the type `struct cmsgcred'. */
 /* #undef HAVE_STRUCT_CMSGCRED */
@@ -410,10 +416,14 @@
 /* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */
 
 /* Define to 1 if the system has the type `struct sockaddr_storage'. */
+#if (_MSC_VER > 1200)
 #define HAVE_STRUCT_SOCKADDR_STORAGE 1
+#endif
 
 /* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */
+#if (_MSC_VER > 1200)
 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
+#endif
 
 /* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */
 /* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */
diff --git a/src/port/thread.c b/src/port/thread.c
index def2fcfa1dac4ee60e442a213e3f01f1ff92bda2..04f42f55b2c717e866a339adc39d77166d0f4f7a 100644
--- a/src/port/thread.c
+++ b/src/port/thread.c
@@ -7,7 +7,7 @@
  *
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/port/thread.c,v 1.33 2006/06/07 22:24:46 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/thread.c,v 1.34 2006/07/06 02:12:32 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -16,8 +16,12 @@
 
 #include <pwd.h>
 #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY)
+#ifdef WIN32
+#include "pthread-win32.h"
+#else
 #include <pthread.h>
 #endif
+#endif
 
 
 /*
diff --git a/src/win32.mak b/src/win32.mak
index 12034cb8a31cff616843c52c179046b49b11b750..1ee53c96d4982bc8d1ec323d38f9dc50d225d893 100644
--- a/src/win32.mak
+++ b/src/win32.mak
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/win32.mak,v 1.12 2006/03/03 23:11:48 momjian Exp $
+# $PostgreSQL: pgsql/src/win32.mak,v 1.13 2006/07/06 02:12:32 momjian Exp $
 
 # Makefile for Microsoft Visual C++ 5.0 (or compat)
 # Top-file makefile for Win32 parts of postgresql.
@@ -13,6 +13,7 @@ NULL=nul
 ALL: 
    cd include
    if not exist pg_config.h copy pg_config.h.win32 pg_config.h
+   if not exist pg_config_os.h copy port\win32.h pg_config_os.h
    cd ..
    cd interfaces\libpq
    nmake /f win32.mak $(MAKEMACRO)