[PATCH] PR libstdc++/89562 use binary mode for file I/O

Jonathan Wakely jwakely@redhat.com
Sun Mar 3 22:24:00 GMT 2019


	PR libstdc++/89562
	* src/filesystem/ops-common.h (do_copy_file): Open files in binary
	mode for mingw.

Tested x86_64-linux, and lightly tested on mingw-w64 to verify the fix
works.


-------------- next part --------------
commit b15e67df3477fac3fea5a3df234be91391719fcd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sun Mar 3 22:01:29 2019 +0000

    PR libstdc++/89562 use binary mode for file I/O
    
            PR libstdc++/89562
            * src/filesystem/ops-common.h (do_copy_file): Open files in binary
            mode for mingw.

diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h
index 55e482ff8f2..6dc9b137dbf 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -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)
       {


More information about the Libstdc++ mailing list