/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
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
#undef major
#undef minor
#undef makedev
#define major(dev) int(((dev) >> 8) & 0xff)
#define minor(dev) int((dev) & 0xff)
#define makedev(majNum, minNum) (((unsigned(majNum)) << 8) | (unsigned(minNum)))
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileStat::fileStat()
:
valid_(false)
{}
Foam::fileStat::fileStat
(
const char* fName,
const bool followLink,
const unsigned int maxTime
)
:
valid_(false)
{
if (!fName || !fName[0])
{
return;
}
// Work on volatile
volatile bool locIsValid = false;
timer myTimer(maxTime);
if (!timedOut(myTimer))
{
#ifdef _WIN32
locIsValid = (::stat(fName, &status_) == 0);
#else
if (followLink)
{
locIsValid = (::stat(fName, &status_) == 0);
}
else
{
locIsValid = (::lstat(fName, &status_) == 0);
}
#endif
}
// Copy into (non-volatile, possible register based) member var
valid_ = locIsValid;
}
Foam::fileStat::fileStat
(
const fileName& fName,
const bool followLink,
const unsigned int maxTime
)
:
fileStat(fName.c_str(), followLink, maxTime)
{}
Foam::fileStat::fileStat(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::fileStat::size() const
{
return valid_ ? label(status_.st_size) : 0;
}
time_t Foam::fileStat::modTime() const
{
return valid_ ? status_.st_mtime : 0;
}
double Foam::fileStat::dmodTime() const
{
return
(
valid_
?
#ifdef __APPLE__
(status_.st_mtime + 1e-9*status_.st_mtimespec.tv_nsec)
#elif defined (_WIN32)
(status_.st_mtime)
#else
(status_.st_mtime + 1e-9*status_.st_mtim.tv_nsec)
#endif
: 0
);
}
bool Foam::fileStat::sameDevice(const fileStat& other) const
{
return
valid_
&& (
major(status_.st_dev) == major(other.status_.st_dev)
&& minor(status_.st_dev) == minor(other.status_.st_dev)
);
}
bool Foam::fileStat::sameINode(const fileStat& other) const
{
return valid_ && (status_.st_ino == other.status_.st_ino);
}
bool Foam::fileStat::sameINode(const label iNode) const
{
return valid_ && (status_.st_ino == ino_t(iNode));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, fileStat& fs)
{
FixedList