--- lib/stat-w32.c	Sat Aug 25 07:32:01 2018
+++ lib/stat-w32.c	Tue Sep 18 16:00:31 2018
@@ -30,6 +30,7 @@
 #include <limits.h>
 #include <string.h>
 #include <unistd.h>
+// needed for broken windows SDKs: #define NMHDR void*
 #include <windows.h>
 
 /* Specification.  */
@@ -132,6 +133,7 @@
   DWORD type = GetFileType (h);
   if (type == FILE_TYPE_DISK)
     {
+      BY_HANDLE_FILE_INFORMATION info;
       if (!initialized)
         initialize ();
 
@@ -148,7 +150,6 @@
          <https://msdn.microsoft.com/en-us/library/aa364953.aspx>
          <https://msdn.microsoft.com/en-us/library/aa364217.aspx>
          The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher.  */
-      BY_HANDLE_FILE_INFORMATION info;
       if (! GetFileInformationByHandle (h, &info))
         goto failed;
 
@@ -225,6 +226,7 @@
       buf->st_ino = 0;
 #endif
 
+      {
       /* st_mode.  */
       unsigned int mode =
         /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ?  */
@@ -274,7 +276,7 @@
             }
         }
       buf->st_mode = mode;
-
+      }
       /* st_nlink can be determined through
          GetFileInformationByHandle
          <https://msdn.microsoft.com/en-us/library/aa364952.aspx>
--- lib/stat.c	Tue May 08 12:02:49 2018
+++ lib/stat.c	Tue Sep 18 15:11:10 2018
@@ -79,8 +79,7 @@
       if (q > p && *q != '\0')
         {
           /* Found the next slash at q.  */
-          q++;
-          const char *r = q;
+          const char *r = ++q;
           while (*r != '\0' && !ISSLASH (*r))
             r++;
           if (r > q && *r == '\0')
@@ -108,6 +107,8 @@
   /* XXX Should we convert to wchar_t* and prepend '\\?\', in order to work
      around length limitations
      <https://msdn.microsoft.com/en-us/library/aa365247.aspx> ?  */
+  size_t len, rlen, drive_prefix_len;
+  bool check_dir = false;
 
   /* POSIX <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>
      specifies: "More than two leading <slash> characters shall be treated as
@@ -119,13 +120,11 @@
         name++;
     }
 
-  size_t len = strlen (name);
-  size_t drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
+  len = strlen (name);
+  drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
 
   /* Remove trailing slashes (except the very first one, at position
      drive_prefix_len), but remember their presence.  */
-  size_t rlen;
-  bool check_dir = false;
 
   rlen = len;
   while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
@@ -150,6 +149,7 @@
       return -1;
     }
 
+  {
   const char *rname;
   char *malloca_rname;
   if (rlen == len)
@@ -218,6 +218,8 @@
 
     /* Fallback.  */
     {
+      WIN32_FIND_DATA info;
+      HANDLE h;
       /* Approach based on the directory entry.  */
 
       if (strchr (rname, '?') != NULL || strchr (rname, '*') != NULL)
@@ -239,8 +241,7 @@
          <https://msdn.microsoft.com/en-us/library/aa364419.aspx>
          <https://msdn.microsoft.com/en-us/library/aa364415.aspx>
          <https://msdn.microsoft.com/en-us/library/aa365740.aspx>  */
-      WIN32_FIND_DATA info;
-      HANDLE h = FindFirstFile (rname, &info);
+      h = FindFirstFile (rname, &info);
       if (h == INVALID_HANDLE_VALUE)
         goto failed;
 
@@ -269,6 +270,7 @@
 # endif
 
       /* st_mode.  */
+      {
       unsigned int mode =
         /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ?  */
         ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
@@ -297,6 +299,7 @@
             }
         }
       buf->st_mode = mode;
+      }
 
       /* st_nlink.  Ignore hard links here.  */
       buf->st_nlink = 1;
@@ -404,6 +407,7 @@
       }
 
     return -1;
+  }
   }
 #else
   int result = orig_stat (name, buf);
