aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-30 12:01:33 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-09-30 14:11:37 +0000
commitfd427a98231c5ab36cba35dee8fc6c4df2fa6e3e (patch)
tree9364856197849ff4d60327fa949de8f0dda8e839 /third_party
parente898023ffc6c47a27312c4d3659dbeeccdb3cd37 (diff)
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
Diffstat (limited to 'third_party')
-rw-r--r--third_party/ijar/common.h5
-rw-r--r--third_party/ijar/mapped_file_windows.cc64
-rw-r--r--third_party/ijar/zip.cc2
3 files changed, 60 insertions, 11 deletions
diff --git a/third_party/ijar/common.h b/third_party/ijar/common.h
index 513e0019a9..05ad19fef8 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 3a928c5191..e96f4d41da 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 @@ namespace devtools_ijar {
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 @@ MappedInputFile::MappedInputFile(const char* name) {
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 @@ MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size) {
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 @@ int MappedOutputFile::Close(int size) {
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 3a56103eae..7b34151b52 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>