Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "fileStat.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 #include "timer.H"
00029
00030 #include <signal.h>
00031 #include <unistd.h>
00032 #include <sys/types.h>
00033
00034
00035
00036 Foam::fileStat::fileStat()
00037 :
00038 isValid_(false)
00039 {}
00040
00041
00042 Foam::fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
00043 {
00044
00045 volatile bool locIsValid = false;
00046
00047 timer myTimer(maxTime);
00048
00049 if (!timedOut(myTimer))
00050 {
00051 if (::stat(fName.c_str(), &status_) != 0)
00052 {
00053 locIsValid = false;
00054 }
00055 else
00056 {
00057 locIsValid = true;
00058 }
00059 }
00060
00061
00062 isValid_ = locIsValid;
00063 }
00064
00065
00066 Foam::fileStat::fileStat(Istream& is)
00067 {
00068 is >> *this;
00069 }
00070
00071
00072
00073
00074 bool Foam::fileStat::sameDevice(const fileStat& stat2) const
00075 {
00076 return
00077 isValid_
00078 && (
00079 major(status_.st_dev) == major(stat2.status().st_dev)
00080 && minor(status_.st_dev) == minor(stat2.status().st_dev)
00081 );
00082 }
00083
00084
00085 bool Foam::fileStat::sameINode(const fileStat& stat2) const
00086 {
00087 return isValid_ && (status_.st_ino == stat2.status().st_ino);
00088 }
00089
00090
00091 bool Foam::fileStat::sameINode(const label iNode) const
00092 {
00093 return isValid_ && (status_.st_ino == ino_t(iNode));
00094 }
00095
00096
00097
00098
00099 Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
00100 {
00101
00102 is.readBegin("fileStat");
00103
00104 label
00105 devMaj, devMin,
00106 ino, mode, uid, gid,
00107 rdevMaj, rdevMin,
00108 size, atime, mtime, ctime;
00109
00110 is >> fStat.isValid_
00111 >> devMaj
00112 >> devMin
00113 >> ino
00114 >> mode
00115 >> uid
00116 >> gid
00117 >> rdevMaj
00118 >> rdevMin
00119 >> size
00120 >> atime
00121 >> mtime
00122 >> ctime;
00123
00124 dev_t st_dev = makedev(devMaj, devMin);
00125 fStat.status_.st_dev = st_dev;
00126
00127 fStat.status_.st_ino = ino;
00128 fStat.status_.st_mode = mode;
00129 fStat.status_.st_uid = uid;
00130 fStat.status_.st_gid = gid;
00131
00132 dev_t st_rdev = makedev(rdevMaj, rdevMin);
00133 fStat.status_.st_rdev = st_rdev;
00134
00135 fStat.status_.st_size = size;
00136 fStat.status_.st_atime = atime;
00137 fStat.status_.st_mtime = mtime;
00138 fStat.status_.st_ctime = ctime;
00139
00140
00141 is.readEnd("fileStat");
00142
00143
00144 is.check("Istream& operator>>(Istream&, fileStat&)");
00145
00146 return is;
00147 }
00148
00149
00150 Foam::Ostream& Foam::operator<<(Ostream& os, const fileStat& fStat)
00151 {
00152
00153
00154 int oldPrecision = 0;
00155 os.precision(10);
00156
00157 os << token::BEGIN_LIST << fStat.isValid_
00158 << token::SPACE << label(major(fStat.status_.st_dev))
00159 << token::SPACE << label(minor(fStat.status_.st_dev))
00160 << token::SPACE << label(fStat.status_.st_ino)
00161 << token::SPACE << label(fStat.status_.st_mode)
00162 << token::SPACE << label(fStat.status_.st_uid)
00163 << token::SPACE << label(fStat.status_.st_gid)
00164 << token::SPACE << label(major(fStat.status_.st_rdev))
00165 << token::SPACE << label(minor(fStat.status_.st_rdev))
00166 << token::SPACE << label(fStat.status_.st_size)
00167 << token::SPACE << label(fStat.status_.st_atime)
00168 << token::SPACE << label(fStat.status_.st_mtime)
00169 << token::SPACE << label(fStat.status_.st_ctime)
00170 << token::END_LIST;
00171
00172 os.precision(oldPrecision);
00173 return os;
00174 }
00175
00176
00177