1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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"
33 #include <sys/sysmacros.h>
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::fileStat::fileStat()
43 Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
46 volatile bool locIsValid = false;
48 timer myTimer(maxTime);
50 if (!timedOut(myTimer))
52 if (::stat(fName.c_str(), &status_) != 0)
62 // Copy into (non-volatile, possible register based) member var
63 isValid_ = locIsValid;
67 Foam::fileStat::fileStat(Istream& is)
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 bool Foam::fileStat::sameDevice(const fileStat& stat2) const
80 major(status_.st_dev) == major(stat2.status().st_dev)
81 && minor(status_.st_dev) == minor(stat2.status().st_dev)
86 bool Foam::fileStat::sameINode(const fileStat& stat2) const
88 return isValid_ && (status_.st_ino == stat2.status().st_ino);
92 bool Foam::fileStat::sameINode(const label iNode) const
94 return isValid_ && (status_.st_ino == ino_t(iNode));
98 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
100 Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
102 // Read beginning of machine info list
103 is.readBegin("fileStat");
109 size, atime, mtime, ctime;
125 dev_t st_dev = makedev(devMaj, devMin);
126 fStat.status_.st_dev = st_dev;
128 fStat.status_.st_ino = ino;
129 fStat.status_.st_mode = mode;
130 fStat.status_.st_uid = uid;
131 fStat.status_.st_gid = gid;
133 dev_t st_rdev = makedev(rdevMaj, rdevMin);
134 fStat.status_.st_rdev = st_rdev;
136 fStat.status_.st_size = size;
137 fStat.status_.st_atime = atime;
138 fStat.status_.st_mtime = mtime;
139 fStat.status_.st_ctime = ctime;
141 // Read end of machine info list
142 is.readEnd("fileStat");
144 // Check state of Istream
145 is.check("Istream& operator>>(Istream&, fileStat&)");
151 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
153 // Set precision so 32bit unsigned int can be printed
154 // int oldPrecision = os.precision();
155 int oldPrecision = 0;
158 os << token::BEGIN_LIST << fStat.isValid_
159 << token::SPACE << label(major(fStat.status_.st_dev))
160 << token::SPACE << label(minor(fStat.status_.st_dev))
161 << token::SPACE << label(fStat.status_.st_ino)
162 << token::SPACE << label(fStat.status_.st_mode)
163 << token::SPACE << label(fStat.status_.st_uid)
164 << token::SPACE << label(fStat.status_.st_gid)
165 << token::SPACE << label(major(fStat.status_.st_rdev))
166 << token::SPACE << label(minor(fStat.status_.st_rdev))
167 << token::SPACE << label(fStat.status_.st_size)
168 << token::SPACE << label(fStat.status_.st_atime)
169 << token::SPACE << label(fStat.status_.st_mtime)
170 << token::SPACE << label(fStat.status_.st_ctime)
173 os.precision(oldPrecision);
178 // ************************************************************************* //