Ijar: make some targets compilable with MSVC

Particulary third_party/ijar:{zip,zlib_client} now
compile with --cpu=x64_windows_msvc.

--
MOS_MIGRATED_REVID=134771232
diff --git a/third_party/ijar/common.h b/third_party/ijar/common.h
index 513e001..05ad19f 100644
--- a/third_party/ijar/common.h
+++ b/third_party/ijar/common.h
@@ -22,6 +22,11 @@
 #include <stdint.h>
 #include <string.h>
 
+#ifdef COMPILER_MSVC
+#define PATH_MAX 4096
+typedef int mode_t;
+#endif  // COMPILER_MSVC
+
 namespace devtools_ijar {
 
 typedef unsigned long long u8;
diff --git a/third_party/ijar/mapped_file_windows.cc b/third_party/ijar/mapped_file_windows.cc
index 3a928c5..e96f4d4 100644
--- a/third_party/ijar/mapped_file_windows.cc
+++ b/third_party/ijar/mapped_file_windows.cc
@@ -12,9 +12,15 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <malloc.h>  // malloc, free
 #include <stdio.h>
 #include <windows.h>
-#include <sys/cygwin.h>
+
+#ifdef COMPILER_MSVC
+#include <stdlib.h>  // exit
+#else  // not COMPILER_MSVC
+#include <sys/cygwin.h>  // cygwin_create_path, CCP_POSIX_TO_WIN_A
+#endif  // COMPILER_MSVC
 
 #include "third_party/ijar/mapped_file.h"
 
@@ -24,6 +30,17 @@
 
 static char errmsg[MAX_ERROR] = "";
 
+class WindowsPath {
+ public:
+  WindowsPath(const char* path);
+  ~WindowsPath();
+  const char* GetWindowsPath() const { return _win_path; }
+
+ private:
+  char* _win_path;
+};
+
+
 void PrintLastError(const char* op) {
   char *message;
   DWORD err = GetLastError();
@@ -62,10 +79,8 @@
   opened_ = false;
   errmsg_ = errmsg;
 
-  char* path = reinterpret_cast<char*>(
-      cygwin_create_path(CCP_POSIX_TO_WIN_A, name));
-  char* unicode_path = ToUnicodePath(path);
-  free(path);
+  WindowsPath path(name);
+  char* unicode_path = ToUnicodePath(path.GetWindowsPath());
   HANDLE file = CreateFile(unicode_path, GENERIC_READ, FILE_SHARE_READ, NULL,
                            OPEN_EXISTING, 0, NULL);
   free(unicode_path);
@@ -147,10 +162,8 @@
   opened_ = false;
   errmsg_ = errmsg;
 
-  char* path = reinterpret_cast<char*>(
-      cygwin_create_path(CCP_POSIX_TO_WIN_A, name));
-  char* unicode_path = ToUnicodePath(path);
-  free(path);
+  WindowsPath path(name);
+  char* unicode_path = ToUnicodePath(path.GetWindowsPath());
   HANDLE file = CreateFile(unicode_path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                            CREATE_ALWAYS, 0, NULL);
   free(unicode_path);
@@ -213,4 +226,37 @@
   return 0;
 }
 
+#ifdef COMPILER_MSVC
+
+  WindowsPath::WindowsPath(const char* path)
+      : _win_path(const_cast<char*>(path)) {
+    // Input path should already be Windows-style, but let's do a sanity check
+    // nevertheless. Not using assert(2) because we need this even in non-debug
+    // builds.
+    if (path[0] == '/') {
+      fprintf(
+          stderr,
+          "ERROR: Illegal state; '%s' is assumed to be a Windows path. This" \
+          " is a programming error, fix" \
+          " third_party/ijar/mapped_file_windows.cc\n",
+          path);
+      exit(1);
+    }
+  }
+
+  WindowsPath::~WindowsPath() {}
+
+#else  // not COMPILER_MSVC
+
+  WindowsPath::WindowsPath(const char* path) {
+    this->_win_path =
+        reinterpret_cast<char*>(cygwin_create_path(CCP_POSIX_TO_WIN_A, path));
+  }
+
+  WindowsPath::~WindowsPath() {
+    free(this->_win_path);
+  }
+
+#endif  // COMPILER_MSVC
+
 }  // namespace devtools_ijar
diff --git a/third_party/ijar/zip.cc b/third_party/ijar/zip.cc
index 3a56103..7b34151 100644
--- a/third_party/ijar/zip.cc
+++ b/third_party/ijar/zip.cc
@@ -30,8 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/mman.h>
-#include <unistd.h>
 #include <limits.h>
 #include <limits>
 #include <vector>