#endif
 #endif
 
-#if !HOST_HAS_O_CLOEXEC
+/* Some open(2) flag differences, what a colourful world it is!  */
+#if defined (O_CLOEXEC)
+// OK
+#elif defined (_O_NOINHERIT)
+/* Windows' _O_NOINHERIT matches O_CLOEXEC flag */
+#define O_CLOEXEC _O_NOINHERIT
+#else
 #define O_CLOEXEC 0
 #endif
+#if defined (O_BINARY)
+// Ok?
+#elif defined (_O_BINARY)
+/* Windows' open(2) call defaults to text!  */
+#define O_BINARY _O_BINARY
+#else
+#define O_BINARY 0
+#endif
 
 static inline cpp_hashnode *cpp_node (tree id)
 {
   gcc_checking_assert (is_frozen ());
   struct stat stat;
 
-  fd = open (name, O_RDONLY | O_CLOEXEC);
+  fd = open (name, O_RDONLY | O_CLOEXEC | O_BINARY);
   if (fd < 0 || fstat (fd, &stat) < 0)
     set_error (errno);
   else
     {
       const char *file = maybe_add_cmi_prefix (filename);
       dump () && dump ("CMI is %s", file);
-      fd = open (file, O_RDONLY | O_CLOEXEC);
+      fd = open (file, O_RDONLY | O_CLOEXEC | O_BINARY);
       e = errno;
     }
 
          if (!errorcount)
            for (unsigned again = 2; ; again--)
              {
-               fd = open (tmp_name, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC,
+               fd = open (tmp_name,
+                          O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC | O_BINARY,
                           S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
                e = errno;
                if (fd >= 0 || !again || e != ENOENT)