/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "fileStat.H"
#include "IOstreams.H"
#include "timer.H"
#include
#include
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileStat::fileStat()
:
isValid_(false)
{}
Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
{
// Work on volatile
volatile bool locIsValid = false;
timer myTimer(maxTime);
if (!timedOut(myTimer))
{
if (::stat(fName.c_str(), &status_) != 0)
{
locIsValid = false;
}
else
{
locIsValid = true;
}
}
// Copy into (non-volatile, possible register based) member var
isValid_ = locIsValid;
}
Foam::fileStat::fileStat(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileStat::sameDevice(const fileStat& stat2) const
{
return
isValid_
&& (
major(status_.st_dev) == major(stat2.status().st_dev)
&& minor(status_.st_dev) == minor(stat2.status().st_dev)
);
}
bool Foam::fileStat::sameINode(const fileStat& stat2) const
{
return isValid_ && (status_.st_ino == stat2.status().st_ino);
}
bool Foam::fileStat::sameINode(const label iNode) const
{
return isValid_ && (status_.st_ino == ino_t(iNode));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
{
FixedList