1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "IOstreams.H"
35 #include <sys/sysmacros.h>
43 # define major(dev) ((int)(((dev) >> 8) & 0xff))
44 # define minor(dev) ((int)((dev) & 0xff))
45 # define makedev(major, minor) ((((unsigned int) (major)) << 8) \
46 | ((unsigned int) (minor)))
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 Foam::fileStat::fileStat()
57 Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
60 volatile bool locIsValid = false;
62 timer myTimer(maxTime);
64 if (!timedOut(myTimer))
66 if (::stat(fName.c_str(), &status_) != 0)
76 // Copy into (non-volatile, possible register based) member var
77 isValid_ = locIsValid;
81 Foam::fileStat::fileStat(Istream& is)
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 bool Foam::fileStat::sameDevice(const fileStat& stat2) const
94 major(status_.st_dev) == major(stat2.status().st_dev)
95 && minor(status_.st_dev) == minor(stat2.status().st_dev)
100 bool Foam::fileStat::sameINode(const fileStat& stat2) const
102 return isValid_ && (status_.st_ino == stat2.status().st_ino);
106 bool Foam::fileStat::sameINode(const label iNode) const
108 return isValid_ && (status_.st_ino == ino_t(iNode));
112 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
114 Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
116 // Read beginning of machine info list
117 is.readBegin("fileStat");
123 size, atime, mtime, ctime;
139 dev_t st_dev = makedev(devMaj, devMin);
140 fStat.status_.st_dev = st_dev;
142 fStat.status_.st_ino = ino;
143 fStat.status_.st_mode = mode;
144 fStat.status_.st_uid = uid;
145 fStat.status_.st_gid = gid;
147 dev_t st_rdev = makedev(rdevMaj, rdevMin);
148 fStat.status_.st_rdev = st_rdev;
150 fStat.status_.st_size = size;
151 fStat.status_.st_atime = atime;
152 fStat.status_.st_mtime = mtime;
153 fStat.status_.st_ctime = ctime;
155 // Read end of machine info list
156 is.readEnd("fileStat");
158 // Check state of Istream
159 is.check("Istream& operator>>(Istream&, fileStat&)");
165 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
167 // Set precision so 32bit unsigned int can be printed
168 // int oldPrecision = os.precision();
169 int oldPrecision = 0;
172 os << token::BEGIN_LIST << fStat.isValid_
173 << token::SPACE << label(major(fStat.status_.st_dev))
174 << token::SPACE << label(minor(fStat.status_.st_dev))
175 << token::SPACE << label(fStat.status_.st_ino)
176 << token::SPACE << label(fStat.status_.st_mode)
177 << token::SPACE << label(fStat.status_.st_uid)
178 << token::SPACE << label(fStat.status_.st_gid)
179 << token::SPACE << label(major(fStat.status_.st_rdev))
180 << token::SPACE << label(minor(fStat.status_.st_rdev))
181 << token::SPACE << label(fStat.status_.st_size)
182 << token::SPACE << label(fStat.status_.st_atime)
183 << token::SPACE << label(fStat.status_.st_mtime)
184 << token::SPACE << label(fStat.status_.st_ctime)
187 os.precision(oldPrecision);
192 // ************************************************************************* //