Mac build fixes.

This gets us pretty close. There are a few problems with libraries we depend
on (system/core/liblog and external/icu4c) that I have workarounds for, and
a problem with gtest that I haven't yet worked around that prevents us from
linking any of the tests. But this at least gives us a Mac dex2oat binary.

Change-Id: Iac39a6c2963c3d37ab2165d7d1a70e303ba22c45
diff --git a/src/zip_archive.cc b/src/zip_archive.cc
index 6105c21..73728a2 100644
--- a/src/zip_archive.cc
+++ b/src/zip_archive.cc
@@ -280,13 +280,28 @@
   }
 }
 
+static void SetCloseOnExec(int fd) {
+  // This dance is more portable than Linux's O_CLOEXEC open(2) flag.
+  int flags = fcntl(fd, F_GETFD);
+  if (flags == -1) {
+    PLOG(WARNING) << "fcntl(" << fd << ", F_GETFD) failed";
+    return;
+  }
+  int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+  if (rc == -1) {
+    PLOG(WARNING) << "fcntl(" << fd << ", F_SETFD, " << flags << ") failed";
+    return;
+  }
+}
+
 ZipArchive* ZipArchive::Open(const std::string& filename) {
   DCHECK(!filename.empty());
-  int fd = open(filename.c_str(), O_RDONLY | O_CLOEXEC, 0);
-  if (fd < 0) {
+  int fd = open(filename.c_str(), O_RDONLY, 0);
+  if (fd == -1) {
     PLOG(WARNING) << "Unable to open '" << filename << "'";
     return NULL;
   }
+  SetCloseOnExec(fd);
   return OpenFromFd(fd);
 }