diff --git a/configure b/configure
index bd84605af0ff807d0bbb51294ec31e37db4cf8a1..afe81d03460aedac45459a9911775845a57fb34c 100755
--- a/configure
+++ b/configure
@@ -11397,7 +11397,8 @@ esac
 # Win32 can't to rename or unlink on an open file
 case $host_os in mingw*)
 LIBOBJS="$LIBOBJS dirmod.$ac_objext"
-LIBOBJS="$LIBOBJS copydir.$ac_objext" ;;
+LIBOBJS="$LIBOBJS copydir.$ac_objext"
+LIBOBJS="$LIBOBJS gettimeofday.$ac_objext" ;;
 esac
 
 if test "$with_readline" = yes; then
diff --git a/configure.in b/configure.in
index 670e5960d7e4c00a8932cd2bedf0d2e0edf7ccd5..51157599a9e9abc4a919dd3fedcc319fd01ca5f9 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.251 2003/05/15 17:59:17 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.252 2003/05/16 01:57:51 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -865,7 +865,8 @@ esac
 # Win32 can't to rename or unlink on an open file
 case $host_os in mingw*)
 AC_LIBOBJ(dirmod)
-AC_LIBOBJ(copydir) ;;
+AC_LIBOBJ(copydir)
+AC_LIBOBJ(gettimeofday) ;;
 esac
 
 if test "$with_readline" = yes; then
diff --git a/src/include/c.h b/src/include/c.h
index f8df3a434c94779345fa5d984f7b54f90915a80b..6f3c690fbc98a7e9238208d5111cd4af4b66c953 100644
--- a/src/include/c.h
+++ b/src/include/c.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: c.h,v 1.146 2003/05/15 23:39:27 tgl Exp $
+ * $Id: c.h,v 1.147 2003/05/16 01:57:51 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -52,7 +52,9 @@
 
 #include "pg_config.h"
 #include "pg_config_manual.h"	/* must be after pg_config.h */
+#ifndef WIN32
 #include "pg_config_os.h"		/* must be before any system header files */
+#endif
 #include "postgres_ext.h"
 
 #include <stdio.h>
@@ -71,6 +73,11 @@
 #include <SupportDefs.h>
 #endif
 
+#ifdef WIN32
+/* We have to redefine some system functions after they are included above */
+#include "pg_config_os.h"
+#endif
+
 /* Must be before gettext() games below */
 #include <locale.h>
 
diff --git a/src/include/port.h b/src/include/port.h
index f5672355bd841f180afeb4824d6d1fb6e6309ced..ef40360ca6568e50f8ebe8cc012068e4a9eae800 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: port.h,v 1.1 2003/05/15 16:35:29 momjian Exp $
+ * $Id: port.h,v 1.2 2003/05/16 01:57:51 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,21 +22,26 @@ int fseeko(FILE *stream, off_t offset, int whence);
 off_t ftello(FILE *stream);
 #endif
 
+#ifdef WIN32
 /*
  * Win32 doesn't have reliable rename/unlink during concurrent access
  */
-#if defined(WIN32) && !defined(FRONTEND)
+#ifndef FRONTEND
 int pgrename(const char *from, const char *to);
 int pgunlink(const char *path);      
 #define rename(from, to)	pgrename(from, to)
 #define unlink(path)		pgunlink(path)
 #endif
 
+extern int copydir(char *fromdir,char *todir);
+extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
+
+#else
+
 /*
  *	Win32 requires a special close for sockets and pipes, while on Unix
  *	close() does them all.
  */
-#ifndef WIN32
 #define	closesocket close
 #endif
   
@@ -45,7 +50,7 @@ int pgunlink(const char *path);
  * When necessary, these routines are provided by files in src/port/.
  */
 #ifndef HAVE_CRYPT
-char *crypt(const char *key, const char *setting);
+extern char *crypt(const char *key, const char *setting);
 #endif
 
 #ifndef HAVE_FSEEKO
@@ -90,4 +95,3 @@ extern long random(void);
 #ifndef HAVE_SRANDOM
 extern void srandom(unsigned int seed);
 #endif
-
diff --git a/src/port/copydir.c b/src/port/copydir.c
index cd39f4d07ee4de004481023833bafd346876ddd4..81a36cca4a337515784cd1093c1f31de17d8950a 100644
--- a/src/port/copydir.c
+++ b/src/port/copydir.c
@@ -6,6 +6,11 @@
 
 #include "postgres.h"
 
+#undef mkdir	/* no reason to use that macro because we ignore the 2nd arg */
+
+#include "dirent.h"
+
+
 int
 copydir(char *fromdir,char *todir)
 {