diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 63e573d5c2bf54ff8bee1db58bfb0a1911a382f4..cd5cd7dce590b11d89b7b4f8813fae8325055e8d 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -10,7 +10,7 @@
  * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.67 2002/06/20 20:29:53 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.68 2002/07/20 05:43:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -714,7 +714,7 @@ fe_getauthname(char *PQerrormsg)
 		char		username[128];
 		DWORD		namesize = sizeof(username) - 1;
 
-		if (GetUserNameFromId(username, &namesize))
+		if (GetUserName(username, &namesize))
 			name = username;
 #else
 		struct passwd *pw = getpwuid(geteuid());
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 630141ed54939674273981cda01fc30482f0a522..19805db98136d5540e36db1fc3f80cfeadd6dc2a 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.189 2002/07/18 02:02:30 ishii Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.190 2002/07/20 05:43:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2717,6 +2717,9 @@ PQclientEncoding(const PGconn *conn)
 int
 PQsetClientEncoding(PGconn *conn, const char *encoding)
 {
+
+#ifdef MULTIBYTE
+
 	char		qbuf[128];
 	static char query[] = "set client_encoding to '%s'";
 	PGresult   *res;
@@ -2748,6 +2751,9 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
 	}
 	PQclear(res);
 	return (status);
+#else
+        return -1; /* Multibyte support isn't compiled in */
+#endif
 }
 
 void
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 32d56948faaed288862538522ff4877f0d880b03..1ef5d62e1bed1d9cdce49cb9adc728b6be14d551 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.9 2002/06/23 20:30:48 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.10 2002/07/20 05:43:31 momjian Exp $
  *	  
  * NOTES
  *	  The client *requires* a valid server certificate.  Since
@@ -110,7 +110,9 @@
 #include "strdup.h"
 #endif
 
+#ifndef WIN32
 #include <pwd.h>
+#endif
 #include <sys/stat.h>
 
 #ifdef USE_SSL
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 07cbe20d56775eec324eea1eaa0463120339a69c..aee2fce13cacdb4946f15c00eb000b220cdadccb 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-int.h,v 1.51 2002/06/20 20:29:54 momjian Exp $
+ * $Id: libpq-int.h,v 1.52 2002/07/20 05:43:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,6 +20,10 @@
 #ifndef LIBPQ_INT_H
 #define LIBPQ_INT_H
 
+#if defined(WIN32) && (!defined(ssize_t))
+  typedef int ssize_t; /* ssize_t doesn't exist in VC (atleast not VC6) */
+#endif 
+
 /* We assume libpq-fe.h has already been included. */
 #include "postgres_fe.h"
 
diff --git a/src/interfaces/libpq/libpqdll.c b/src/interfaces/libpq/libpqdll.c
index 2fd6cfc7de5ca7e9975ba0263b656bed90c86724..f145d3e0e4e470370e3b7f369356e421ca683d19 100644
--- a/src/interfaces/libpq/libpqdll.c
+++ b/src/interfaces/libpq/libpqdll.c
@@ -1,4 +1,5 @@
 #define WIN32_LEAN_AND_MEAN
+#include <winsock.h>
 #include <windows.h>
 #include "win32.h"
 
diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c
index 2e90c3dad30b9238b30c36fa7442528f7910154a..4b577e3bfc14c9e16847406576834e484c28492c 100644
--- a/src/interfaces/libpq/win32.c
+++ b/src/interfaces/libpq/win32.c
@@ -17,7 +17,14 @@
  *
  */
 
+/* Make stuff compile faster by excluding not used stuff */
+
 #define WIN32_LEAN_AND_MEAN
+#define WIN32_EXTRA_LEAN
+#define VC_EXTRALEAN
+#define NOGDI
+#define NOCRYPT
+
 #include <windows.h>
 #include <winsock.h>
 #include <stdio.h>
diff --git a/src/interfaces/libpq/win32.h b/src/interfaces/libpq/win32.h
index bf6d01b7ca97557584495eaca4c5520eb63c1f37..db1aa53b24fba141408c1b2de5eb62df7376fba8 100644
--- a/src/interfaces/libpq/win32.h
+++ b/src/interfaces/libpq/win32.h
@@ -1,4 +1,5 @@
-#include <winsock.h>
+#ifndef __win32_h_included
+#define __win32_h_included
 
 /*
  * strcasecmp() is not in Windows, stricmp is, though
@@ -34,3 +35,6 @@
  * support for handling Windows Socket errors
  */
 extern const char *winsock_strerror(int eno);
+
+
+#endif
diff --git a/src/interfaces/libpq/win32.mak b/src/interfaces/libpq/win32.mak
index 98b4e986ef9401c854bc24aa1365a884878bb50f..766d33ce08abef02b46763fe39cdb3dc9c93a611 100644
--- a/src/interfaces/libpq/win32.mak
+++ b/src/interfaces/libpq/win32.mak
@@ -30,6 +30,15 @@ CFG=Release
 !ERROR An invalid configuration was specified.
 !ENDIF
 
+!IFDEF DEBUG
+OPT=/Od
+LOPT=/debug
+DEBUGDEF=/D _DEBUG
+!ELSE
+OPT=/O2
+LOPT=
+DEBUGDEF=/D NDEBUG
+!ENDIF
 
 !IF "$(OS)" == "Windows_NT"
 NULL=
@@ -62,6 +71,7 @@ CLEAN :
 	-@erase "$(INTDIR)\fe-lobj.obj"
 	-@erase "$(INTDIR)\fe-misc.obj"
 	-@erase "$(INTDIR)\fe-print.obj"
+	-@erase "$(INTDIR)\fe-secure.obj"
 	-@erase "$(INTDIR)\pqexpbuffer.obj"
 	-@erase "$(OUTDIR)\libpqdll.obj"
 	-@erase "$(OUTDIR)\win32.obj"
@@ -80,7 +90,7 @@ CLEAN :
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
-CPP_PROJ=/nologo /MD /W3 /GX /O2 /I "..\..\include" /D "FRONTEND" /D "NDEBUG" /D\
+CPP_PROJ=/nologo /MD /W3 /GX $(OPT) /I "..\..\include" /D "FRONTEND" $(DEBUGDEF) /D\
  "WIN32" /D "_WINDOWS" /Fp"$(INTDIR)\libpq.pch" /YX\
  /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c  /D "HAVE_VSNPRINTF" /D "HAVE_STRDUP"
 
@@ -95,7 +105,7 @@ CPP_OBJS=.\Release/
 CPP_SBRS=.
 	
 LIB32=link.exe -lib
-LIB32_FLAGS=/nologo /out:"$(OUTDIR)\libpq.lib" 
+LIB32_FLAGS=$(LOPT) /nologo /out:"$(OUTDIR)\libpq.lib" 
 LIB32_OBJS= \
 	"$(OUTDIR)\win32.obj" \
 	"$(INTDIR)\dllist.obj" \
@@ -106,6 +116,7 @@ LIB32_OBJS= \
 	"$(INTDIR)\fe-lobj.obj" \
 	"$(INTDIR)\fe-misc.obj" \
 	"$(INTDIR)\fe-print.obj" \
+	"$(INTDIR)\fe-secure.obj" \
 	"$(INTDIR)\pqexpbuffer.obj"
 
 !IFDEF MULTIBYTE
@@ -116,7 +127,7 @@ RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res"
 
 LINK32=link.exe
 LINK32_FLAGS=kernel32.lib user32.lib advapi32.lib wsock32.lib\
- /nologo /subsystem:windows /dll /incremental:no\
+ /nologo /subsystem:windows /dll $(LOPT) /incremental:no\
  /pdb:"$(OUTDIR)\libpqdll.pdb" /machine:I386 /out:"$(OUTDIR)\libpq.dll"\
  /implib:"$(OUTDIR)\libpqdll.lib"  /def:libpqdll.def
 LINK32_OBJS= \