PR libstdc++/89562 use binary mode for file I/O
authorJonathan Wakely <jwakely@redhat.com>
Sun, 3 Mar 2019 22:23:33 +0000 (22:23 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Sun, 3 Mar 2019 22:23:33 +0000 (22:23 +0000)
PR libstdc++/89562
* src/filesystem/ops-common.h (do_copy_file): Open files in binary
mode for mingw.

From-SVN: r269356

libstdc++-v3/ChangeLog
libstdc++-v3/src/filesystem/ops-common.h

index 9c4ef40..70cfef0 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-03  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/89562
+       * src/filesystem/ops-common.h (do_copy_file): Open files in binary
+       mode for mingw.
+
 2019-03-01  Jonathan Wakely  <jwakely@redhat.com>
 
        * testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource)
index 55e482f..6dc9b13 100644 (file)
@@ -402,7 +402,12 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
       int fd;
     };
 
-    CloseFD in = { posix::open(from, O_RDONLY) };
+    int iflag = O_RDONLY;
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+    iflag |= O_BINARY;
+#endif
+
+    CloseFD in = { posix::open(from, iflag) };
     if (in.fd == -1)
       {
        ec.assign(errno, std::generic_category());
@@ -413,6 +418,9 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
       oflag |= O_TRUNC;
     else
       oflag |= O_EXCL;
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+    oflag |= O_BINARY;
+#endif
     CloseFD out = { posix::open(to, oflag, S_IWUSR) };
     if (out.fd == -1)
       {