diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
old mode 100644
new mode 100755
index 2755df9..1744679
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -122,6 +122,8 @@ __realpath (const char *name, char *resolved)
 
 #ifdef PATH_MAX
   path_max = PATH_MAX;
+#elif defined _MSC_VER
+  path_max = 260;
 #else
   path_max = pathconf (name, _PC_PATH_MAX);
   if (path_max <= 0)
diff --git a/lib/fopen.c b/lib/fopen.c
old mode 100644
new mode 100755
index 81c8617..38fd71a
--- a/lib/fopen.c
+++ b/lib/fopen.c
@@ -16,7 +16,9 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+#define _GL_ALREADY_INCLUDING_STDIO_H
 #include <config.h>
+#undef _GL_ALREADY_INCLUDING_STDIO_H
 
 /* Get the original definition of fopen.  It might be defined as a macro.  */
 #define __need_FILE
diff --git a/lib/glob.c b/lib/glob.c
index 85419cc..fe9a2b9 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -1342,9 +1342,20 @@ glob_in_dir (const char *pattern, const char *directory, int flags,
       size_t patlen = strlen (pattern);
       char *fullname = __alloca (dirlen + 1 + patlen + 1);
 
-      mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
-                        "/", 1),
-               pattern, patlen + 1);
+      if (dirlen > 0 && directory[dirlen - 1] == '/')
+	{
+	  /* DIRECTORY already has a trailing slash. No need
+	     to add another one. This might confuse the system
+	     stat() function.  */
+	  mempcpy (mempcpy (fullname, directory, dirlen),
+		   pattern, patlen + 1);
+	}
+      else
+	{
+	  mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
+			    "/", 1),
+		   pattern, patlen + 1);
+	}
       if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
            ? (*pglob->gl_stat) (fullname, &st)
            : __stat64 (fullname, &st64)) == 0)
diff --git a/lib/open.c b/lib/open.c
old mode 100644
new mode 100755
index e60b619..d3fec1f
--- a/lib/open.c
+++ b/lib/open.c
@@ -120,8 +120,8 @@ open (const char *filename, int flags, ...)
      override fstat() in fchdir.c to hide the fact that we have a
      dummy.  */
   if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
-      && ((flags & O_ACCMODE) == O_RDONLY
-          || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
+      && ((flags & (O_RDONLY|O_WRONLY|O_RDWR)) == O_RDONLY
+          || (O_SEARCH != O_RDONLY && (flags & (O_RDONLY|O_WRONLY|O_RDWR)) == O_SEARCH)))
     {
       struct stat statbuf;
       if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
diff --git a/lib/pathmax.h b/lib/pathmax.h
old mode 100644
new mode 100755
index a1e458c..6620bdf
--- a/lib/pathmax.h
+++ b/lib/pathmax.h
@@ -66,4 +66,8 @@
 #  define PATH_MAX 1024
 # endif
 
+# if ! defined PATH_MAX && defined _MSC_VER
+#  define PATH_MAX 260
+# endif
+
 #endif /* _PATHMAX_H */
diff --git a/lib/stat.c b/lib/stat.c
old mode 100644
new mode 100755
index f07370d..a2ba56f
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -66,7 +66,7 @@ rpl_stat (char const *name, struct stat *st)
 #if REPLACE_FUNC_STAT_DIR
   /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
      have a constant PATH_MAX.  */
-# ifndef PATH_MAX
+# if ! defined PATH_MAX && ! defined _MSC_VER
 #  error "Please port this replacement to your platform"
 # endif
 
@@ -81,7 +81,13 @@ rpl_stat (char const *name, struct stat *st)
          ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
          Fortunately, mingw PATH_MAX is small enough for stack
          allocation.  */
+#ifdef _MSC_VER
+# define PATH_MAX 260
+# define PATH_MAX_1 261
+      char fixed_name[PATH_MAX_1] = {0};
+#else
       char fixed_name[PATH_MAX + 1] = {0};
+#endif
       size_t len = strlen (name);
       bool check_dir = false;
       verify (PATH_MAX <= 4096);
diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h
index ce70370..2bc416d 100644
--- a/lib/sys_time.in.h
+++ b/lib/sys_time.in.h
@@ -53,11 +53,15 @@ extern "C" {
 # if ! @HAVE_STRUCT_TIMEVAL@
 
 #  if !GNULIB_defined_struct_timeval
+#   if defined(_MSC_VER)
+#    include <winsock2.h>
+#   else
 struct timeval
 {
   time_t tv_sec;
   long int tv_usec;
 };
+#   endif
 #   define GNULIB_defined_struct_timeval 1
 #  endif
 
diff --git a/lib/tempname.c b/lib/tempname.c
index 139e0c3..16747a4 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -265,7 +265,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
         {
         case __GT_FILE:
           fd = __open (tmpl,
-                       (flags & ~O_ACCMODE)
+                       (flags & ~(O_RDONLY|O_WRONLY|O_RDWR))
                        | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
           break;
 
diff --git a/lib/tmpdir.c b/lib/tmpdir.c
old mode 100644
new mode 100755
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index c1cfb54..1dd395c 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -103,6 +103,9 @@
      || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
 /* Get ssize_t.  */
 # include <sys/types.h>
+# ifdef _MSC_VER
+typedef int ssize_t;
+# endif
 #endif
 
 /* Get getopt(), optarg, optind, opterr, optopt.
diff --git a/m4/absolute-header.m4 b/m4/absolute-header.m4
index dba8dbf..eead483 100644
--- a/m4/absolute-header.m4
+++ b/m4/absolute-header.m4
@@ -70,8 +70,8 @@ AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
   dnl so use subshell.
   AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
 [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
-sed -n '\#/$1#{
-        s#.*"\(.*/$1\)".*#\1#
+sed -n '\#[/\\]$1#{
+        s#.*"\(.*[\\/]$1\)".*#\1#
         s#^/[^/]#//&#
         p
         q
diff --git a/m4/include_next.m4 b/m4/include_next.m4
index ebf081a..62bdc77 100644
--- a/m4/include_next.m4
+++ b/m4/include_next.m4
@@ -212,8 +212,8 @@ dnl until we can assume autoconf 2.64 or newer.
                dnl so use subshell.
                AS_VAR_SET(gl_next_header,
                  ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
-                  sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
-                    s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
+                  sed -n '\#[\\/]]m4_defn([gl_HEADER_NAME])[#{
+                    s#.*"\(.*[\\/]]m4_defn([gl_HEADER_NAME])[\)".*#\1#
                     s#^/[^/]#//&#
                     p
                     q
diff --git a/m4/rename.m4 b/m4/rename.m4
index c938b0d..1c1bc46 100644
--- a/m4/rename.m4
+++ b/m4/rename.m4
@@ -122,6 +122,7 @@ AC_DEFUN([gl_FUNC_RENAME],
 #          include <unistd.h>
            ]],
            [[int result = 0;
+#ifndef _MSC_VER
              if (rename ("conftest.f", "conftest.f1"))
                result |= 1;
              if (unlink ("conftest.f1"))
@@ -130,6 +131,7 @@ AC_DEFUN([gl_FUNC_RENAME],
                result |= 4;
              if (rename ("conftest.f1", "conftest.f1") == 0)
                result |= 8;
+#endif
              return result;
            ]])],
         [gl_cv_func_rename_link_works=yes],
