diff --git a/ChangeLog b/ChangeLog
index f100f324..d4b9adbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-20 Joerg Wunsch <j@uriah.heep.sax.de>
+
+	* configure.ac: Check for gettimeofday().
+	* ppiwin.c (gettimeofday): Define gettimeofday() replacement
+	only if !defined(HAVE_GETTIMEOFDAY); use correct protype.
+
 2006-08-18 Joerg Wunsch <j@uriah.heep.sax.de>
 
 	* stk500v2: Minor cosmetic changes: STK500 firmware version
diff --git a/configure.ac b/configure.ac
index fe17d7e9..5f57d0b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,7 +65,7 @@ AC_HEADER_TIME
 # Checks for library functions.
 AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MALLOC
-AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul])
+AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul gettimeofday])
 
 # Checks for misc stuff.
 
diff --git a/ppiwin.c b/ppiwin.c
index 7e274331..f5be6517 100644
--- a/ppiwin.c
+++ b/ppiwin.c
@@ -1,6 +1,7 @@
 /*
  * avrdude - A Downloader/Uploader for AVR device programmers
- * Copyright (C) 2003, 2004  Eric B. Weddington <ericw@evcohs.com>
+ * Copyright (C) 2003, 2004, 2006
+ *    Eric B. Weddington <eweddington@cso.atmel.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,7 +30,7 @@ reg = register as defined in an enum in ppi.h. This must be converted
 */
 
 
-
+#include "ac_cfg.h"
 
 #if defined (WIN32NATIVE)
 
@@ -316,7 +317,8 @@ static void outb(unsigned char value, unsigned short port)
     return;
 }
 
-void gettimeofday(struct timeval*tv, void*z){
+#if !defined(HAVE_GETTIMEOFDAY)
+int gettimeofday(struct timeval *tv, struct timezone *unused){
 // i've found only ms resolution, avrdude expects us
 
 	SYSTEMTIME st;
@@ -324,7 +326,10 @@ void gettimeofday(struct timeval*tv, void*z){
   
 	tv->tv_sec=(long)(st.wSecond+st.wMinute*60+st.wHour*3600);
 	tv->tv_usec=(long)(st.wMilliseconds*1000);
+
+	return 0;
 }
+#endif /* HAVE_GETTIMEOFDAY */
 
 // #define W32USLEEPDBG