diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index a63d3d746e..e09b2055a5 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -34,14 +34,11 @@ Description #include "OSspecific.H" #include "POSIX.H" -#include "foamVersion.H" #include "fileName.H" #include "fileStat.H" #include "timer.H" -#include "IFstream.H" #include "DynamicList.H" #include "CStringList.H" -#include "SubList.H" #include "IOstreams.H" #include "Pstream.H" @@ -49,7 +46,7 @@ Description #include #include -#include +#include #include #include #include @@ -896,14 +893,14 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink) return false; } - // Open and check streams. - std::ifstream srcStream(src); + // Open and check streams. Enforce binary for extra safety + std::ifstream srcStream(src, ios_base::in | ios_base::binary); if (!srcStream) { return false; } - std::ofstream destStream(destFile); + std::ofstream destStream(destFile, ios_base::out | ios_base::binary); if (!destStream) { return false; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index a4908d9c7a..00562483a9 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -52,7 +52,9 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) } } - allocatedPtr_ = new std::ifstream(pathname); + const std::ios_base::openmode mode(std::ios_base::in|std::ios_base::binary); + + allocatedPtr_ = new std::ifstream(pathname, mode); // If the file is compressed, decompress it before reading. if (!allocatedPtr_->good() && isFile(pathname + ".gz", false)) @@ -63,7 +65,7 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) } delete allocatedPtr_; - allocatedPtr_ = new igzstream((pathname + ".gz").c_str()); + allocatedPtr_ = new igzstream((pathname + ".gz").c_str(), mode); if (allocatedPtr_->good()) { diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index 709b0f07d3..027b7c82e2 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -55,7 +55,7 @@ Foam::Detail::OFstreamAllocator::OFstreamAllocator } } - std::ios_base::openmode mode(std::ios_base::out); + std::ios_base::openmode mode(std::ios_base::out|std::ios_base::binary); if (append) { mode |= std::ios_base::app;