1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
32 #include <sys/sysmacros.h>
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::fileStat::fileStat()
42 Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
45 volatile bool locIsValid = false;
47 timer myTimer(maxTime);
49 if (!timedOut(myTimer))
51 if (::stat(fName.c_str(), &status_) != 0)
61 // Copy into (non-volatile, possible register based) member var
62 isValid_ = locIsValid;
66 Foam::fileStat::fileStat(Istream& is)
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 bool Foam::fileStat::sameDevice(const fileStat& stat2) const
79 major(status_.st_dev) == major(stat2.status().st_dev)
80 && minor(status_.st_dev) == minor(stat2.status().st_dev)
85 bool Foam::fileStat::sameINode(const fileStat& stat2) const
87 return isValid_ && (status_.st_ino == stat2.status().st_ino);
91 bool Foam::fileStat::sameINode(const label iNode) const
93 return isValid_ && (status_.st_ino == ino_t(iNode));
97 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
99 Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
101 FixedList<label, 13> stat(is);
103 fStat.isValid_ = stat[0];
105 dev_t st_dev = makedev(stat[1], stat[2]);
106 fStat.status_.st_dev = st_dev;
108 fStat.status_.st_ino = stat[3];
109 fStat.status_.st_mode = stat[4];
110 fStat.status_.st_uid = stat[5];
111 fStat.status_.st_gid = stat[6];
113 dev_t st_rdev = makedev(stat[7], stat[8]);
114 fStat.status_.st_rdev = st_rdev;
116 fStat.status_.st_size = stat[9];
117 fStat.status_.st_atime = stat[10];
118 fStat.status_.st_mtime = stat[11];
119 fStat.status_.st_ctime = stat[12];
121 // Check state of Istream
122 is.check("Istream& operator>>(Istream&, fileStat&)");
128 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
130 FixedList<label, 13> stat;
132 stat[0] = label(fStat.isValid_);
133 stat[1] = label(major(fStat.status_.st_dev));
134 stat[2] = label(minor(fStat.status_.st_dev));
135 stat[3] = label(fStat.status_.st_ino);
136 stat[4] = label(fStat.status_.st_mode);
137 stat[5] = label(fStat.status_.st_uid);
138 stat[6] = label(fStat.status_.st_gid);
139 stat[7] = label(major(fStat.status_.st_rdev));
140 stat[8] = label(minor(fStat.status_.st_rdev));
141 stat[9] = label(fStat.status_.st_size);
142 stat[10] = label(fStat.status_.st_atime);
143 stat[11] = label(fStat.status_.st_mtime);
144 stat[12] = label(fStat.status_.st_ctime);
150 // ************************************************************************* //