1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
34 #include <sys/sysmacros.h>
42 # define major(dev) ((int)(((dev) >> 8) & 0xff))
43 # define minor(dev) ((int)((dev) & 0xff))
44 # define makedev(major, minor) ((((unsigned int) (major)) << 8) \
45 | ((unsigned int) (minor)))
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::fileStat::fileStat()
56 Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
59 volatile bool locIsValid = false;
61 timer myTimer(maxTime);
63 if (!timedOut(myTimer))
65 if (::stat(fName.c_str(), &status_) != 0)
75 // Copy into (non-volatile, possible register based) member var
76 isValid_ = locIsValid;
80 Foam::fileStat::fileStat(Istream& is)
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 bool Foam::fileStat::sameDevice(const fileStat& stat2) const
93 major(status_.st_dev) == major(stat2.status().st_dev)
94 && minor(status_.st_dev) == minor(stat2.status().st_dev)
99 bool Foam::fileStat::sameINode(const fileStat& stat2) const
101 return isValid_ && (status_.st_ino == stat2.status().st_ino);
105 bool Foam::fileStat::sameINode(const label iNode) const
107 return isValid_ && (status_.st_ino == ino_t(iNode));
111 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
113 Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
115 // Read beginning of machine info list
116 is.readBegin("fileStat");
122 size, atime, mtime, ctime;
138 dev_t st_dev = makedev(devMaj, devMin);
139 fStat.status_.st_dev = st_dev;
141 fStat.status_.st_ino = ino;
142 fStat.status_.st_mode = mode;
143 fStat.status_.st_uid = uid;
144 fStat.status_.st_gid = gid;
146 dev_t st_rdev = makedev(rdevMaj, rdevMin);
147 fStat.status_.st_rdev = st_rdev;
149 fStat.status_.st_size = size;
150 fStat.status_.st_atime = atime;
151 fStat.status_.st_mtime = mtime;
152 fStat.status_.st_ctime = ctime;
154 // Read end of machine info list
155 is.readEnd("fileStat");
157 // Check state of Istream
158 is.check("Istream& operator>>(Istream&, fileStat&)");
164 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
166 // Set precision so 32bit unsigned int can be printed
167 // int oldPrecision = os.precision();
168 int oldPrecision = 0;
171 os << token::BEGIN_LIST << fStat.isValid_
172 << token::SPACE << label(major(fStat.status_.st_dev))
173 << token::SPACE << label(minor(fStat.status_.st_dev))
174 << token::SPACE << label(fStat.status_.st_ino)
175 << token::SPACE << label(fStat.status_.st_mode)
176 << token::SPACE << label(fStat.status_.st_uid)
177 << token::SPACE << label(fStat.status_.st_gid)
178 << token::SPACE << label(major(fStat.status_.st_rdev))
179 << token::SPACE << label(minor(fStat.status_.st_rdev))
180 << token::SPACE << label(fStat.status_.st_size)
181 << token::SPACE << label(fStat.status_.st_atime)
182 << token::SPACE << label(fStat.status_.st_mtime)
183 << token::SPACE << label(fStat.status_.st_ctime)
186 os.precision(oldPrecision);
191 // ************************************************************************* //