Index: libtransmission/log.c
===================================================================
--- libtransmission/log.c	(revision 14191)
+++ libtransmission/log.c	(working copy)
@@ -158,7 +158,7 @@
   time_t seconds;
   int milliseconds;
 
-  gettimeofday (&tv, NULL);
+  tr_gettimeofday (&tv);
 
   seconds = tv.tv_sec;
   tr_localtime_r (&seconds, &now_tm);
Index: libtransmission/session.c
===================================================================
--- libtransmission/session.c	(revision 14191)
+++ libtransmission/session.c	(working copy)
@@ -669,7 +669,7 @@
   **/
 
   /* schedule the next timer for right after the next second begins */
-  gettimeofday (&tv, NULL);
+  tr_gettimeofday (&tv);
   usec = 1000000 - tv.tv_usec;
   if (usec > max)
     usec = max;
Index: libtransmission/utils.c
===================================================================
--- libtransmission/utils.c	(revision 14191)
+++ libtransmission/utils.c	(working copy)
@@ -49,10 +51,8 @@
  #include <w32api.h>
  #define WINVER WindowsXP /* freeaddrinfo (), getaddrinfo (), getnameinfo () */
  #include <direct.h> /* _getcwd () */
- #include <windows.h> /* Sleep () */
+ #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime () */
 #endif
 
 #include "transmission.h"
@@ -86,6 +86,41 @@
 #endif
 }
 
+int
+tr_gettimeofday (struct timeval * tv)
+{
+#ifdef _MSC_VER
+
+#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+
+  FILETIME ft;
+  uint64_t tmp = 0;
+
+  if (tv == NULL)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  GetSystemTimeAsFileTime(&ft);
+  tmp |= ft.dwHighDateTime;
+  tmp <<= 32;
+  tmp |= ft.dwLowDateTime;
+  tmp /= 10; /* to microseconds */
+  tmp -= DELTA_EPOCH_IN_MICROSECS;
+
+  tv->tv_sec = tmp / 1000000UL;
+  tv->tv_usec = tmp % 1000000UL;
+
+  return 0;
+
+#undef DELTA_EPOCH_IN_MICROSECS
+
+#else
+  return gettimeofday (tv);
+#endif
+}
+
 /***
 ****
 ***/
@@ -251,19 +286,61 @@
 char*
 tr_basename (const char * path)
 {
+#ifdef _MSC_VER
+  char fname[_MAX_FNAME], ext[_MAX_EXT];
+  if (_splitpath_s (path, NULL, 0, NULL, 0, fname, sizeof (fname), ext, sizeof (ext)) == 0)
+    {
+      const size_t tmpLen = strlen (fname) + strlen (ext) + 2;
+      char * const tmp = tr_malloc (tmpLen);
+      if (tmp != NULL)
+        {
+          if (_makepath_s (tmp, tmpLen, NULL, NULL, fname, ext) == 0)
+            return tmp;
+
+          tr_free (tmp);
+        }
+    }
+
+  return tr_strdup (".");
+#else
   char * tmp = tr_strdup (path);
   char * ret = tr_strdup (basename (tmp));
   tr_free (tmp);
   return ret;
+#endif
 }
 
 char*
 tr_dirname (const char * path)
 {
+#ifdef _MSC_VER
+  char drive[_MAX_DRIVE], dir[_MAX_DIR];
+  if (_splitpath_s (path, drive, sizeof (drive), dir, sizeof (dir), NULL, 0, NULL, 0) == 0)
+    {
+      const size_t tmpLen = strlen (drive) + strlen (dir) + 2;
+      char * const tmp = tr_malloc (tmpLen);
+      if (tmp != NULL)
+        {
+          if (_makepath_s (tmp, tmpLen, drive, dir, NULL, NULL) == 0)
+            {
+              size_t len = strlen (tmp);
+              while (len > 0 && (tmp[len - 1] == '/' || tmp[len - 1] == '\\'))
+                tmp[--len] = '\0';
+
+              return tmp;
+            }
+
+          tr_free (tmp);
+        }
+    }
+
+  return tr_strdup (".");
+#else
   char * tmp = tr_strdup (path);
   char * ret = tr_strdup (dirname (tmp));
   tr_free (tmp);
   return ret;
+#endif
 }
 
 char*
@@ -650,7 +727,7 @@
 {
   struct timeval tv;
 
-  gettimeofday (&tv, NULL);
+  tr_gettimeofday (&tv);
   return (uint64_t) tv.tv_sec * 1000 + (tv.tv_usec / 1000);
 }
 
Index: libtransmission/utils.h
===================================================================
--- libtransmission/utils.h	(revision 14191)
+++ libtransmission/utils.h	(working copy)
@@ -388,7 +388,12 @@
 /** @brief Portability wrapper for localtime_r () that uses the system implementation if available */
 struct tm * tr_localtime_r (const time_t *_clock, struct tm *_result);
 
+struct timeval;
 
+/** @brief Portability wrapper for gettimeofday (), with tz argument dropped */
+int tr_gettimeofday (struct timeval * tv);
+
+
 /**
  * @brief move a file
  * @return 0 on success; otherwise, return -1 and set errno
