mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: open standard file streams with ios_base::binary
- this improves overall consistency and is independent of higher level tagging as ASCII or BINARY for IFstream, OFstream etc.
This commit is contained in:
committed by
Andrew Heather
parent
567fced30b
commit
36fae9fd98
@ -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 <cstdlib>
|
||||
#include <cctype>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
@ -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;
|
||||
|
||||
@ -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())
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user