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