1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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 // Read beginning of machine info list
102 is.readBegin("fileStat");
108 size, atime, mtime, ctime;
124 dev_t st_dev = makedev(devMaj, devMin);
125 fStat.status_.st_dev = st_dev;
127 fStat.status_.st_ino = ino;
128 fStat.status_.st_mode = mode;
129 fStat.status_.st_uid = uid;
130 fStat.status_.st_gid = gid;
132 dev_t st_rdev = makedev(rdevMaj, rdevMin);
133 fStat.status_.st_rdev = st_rdev;
135 fStat.status_.st_size = size;
136 fStat.status_.st_atime = atime;
137 fStat.status_.st_mtime = mtime;
138 fStat.status_.st_ctime = ctime;
140 // Read end of machine info list
141 is.readEnd("fileStat");
143 // Check state of Istream
144 is.check("Istream& operator>>(Istream&, fileStat&)");
150 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
152 // Set precision so 32bit unsigned int can be printed
153 // int oldPrecision = os.precision();
154 int oldPrecision = 0;
157 os << token::BEGIN_LIST << fStat.isValid_
158 << token::SPACE << label(major(fStat.status_.st_dev))
159 << token::SPACE << label(minor(fStat.status_.st_dev))
160 << token::SPACE << label(fStat.status_.st_ino)
161 << token::SPACE << label(fStat.status_.st_mode)
162 << token::SPACE << label(fStat.status_.st_uid)
163 << token::SPACE << label(fStat.status_.st_gid)
164 << token::SPACE << label(major(fStat.status_.st_rdev))
165 << token::SPACE << label(minor(fStat.status_.st_rdev))
166 << token::SPACE << label(fStat.status_.st_size)
167 << token::SPACE << label(fStat.status_.st_atime)
168 << token::SPACE << label(fStat.status_.st_mtime)
169 << token::SPACE << label(fStat.status_.st_ctime)
172 os.precision(oldPrecision);
177 // ************************************************************************* //