00001 // ************************************************************** 00002 // Com ++ Framework by the C++ World 00003 // Please report defects: mailto:compp@cplusplusworld.com 00004 // Please visit: http://www.cplusplusworld.com/socketlibrary.html 00005 // ************************************************************** 00006 00007 #include "ComPlusPlus/DirEntry.h" 00008 #include <string.h> 00009 00010 00011 00012 compp::DirEntry::DirEntry() { 00013 00014 00015 } 00016 00017 void compp::DirEntry::setPath(const std::string & Path) { 00018 00019 if ( 0 != stat( Path.c_str(), & StatStructure) ) { 00020 std::string s = "Cannot stat " ; 00021 s += Path; 00022 throw syspp::ComException ( s.c_str() ); 00023 } 00024 00025 this->Name = Path; 00026 00027 } 00028 00029 compp::DirEntry::DirEntry(const struct dirent & Entry) { 00030 00031 00032 if ( 0 != stat( Entry.d_name, & StatStructure) ) { 00033 std::string s = "Cannot stat " ; 00034 s += Entry.d_name; 00035 throw syspp::ComException ( s.c_str() ); 00036 } 00037 00038 Name = Entry.d_name; 00039 00040 } 00041 00042 00043 compp::DirEntry::DirEntry ( const std::string & dName ) { 00044 00045 if ( 0 != stat( dName.c_str(), & StatStructure) ) { 00046 std::string s = "Cannot stat " ; 00047 s += dName; 00048 throw syspp::ComException ( s.c_str() ); 00049 } 00050 00051 this->Name = dName; 00052 } 00053 00054 compp::DirEntry::DirEntry ( const unsigned int Inode ) { 00055 00056 throw syspp::ComException ( "Sot supported yet. Sorry." ); 00057 00058 } 00059 00060 00061 compp::DirEntry::~DirEntry() { 00062 00063 00064 00065 00066 } 00067 00068 bool compp::DirEntry::lessName ( const compp::DirEntry & LeftEntry, const compp::DirEntry & RightEntry ) { 00069 00070 int i; 00071 00072 i = strcmp ( LeftEntry.getName().c_str(), RightEntry.getName().c_str() ) ; 00073 00074 if ( i < 0 ) 00075 return true; 00076 00077 return false; 00078 00079 } 00080 00081 00082 bool compp::DirEntry::greaterName ( const compp::DirEntry & LeftEntry, const compp::DirEntry & RightEntry ) { 00083 00084 int i; 00085 00086 i = strcmp ( LeftEntry.getName().c_str(), RightEntry.getName().c_str() ) ; 00087 00088 if ( i > 0 ) 00089 return true; 00090 00091 return false; 00092 00093 } 00094 00095 const bool compp::DirEntry::isDirectory () const { 00096 00097 if ( S_ISDIR (StatStructure.st_mode) ) 00098 return true; 00099 00100 return false; 00101 00102 } 00103 00104 const bool compp::DirEntry::isRegularFile() const { 00105 00106 if ( S_ISREG (StatStructure.st_mode) ) 00107 return true; 00108 00109 return false; 00110 00111 } 00112 00113 const bool compp::DirEntry::isCharDevice () const { 00114 00115 if ( S_ISCHR (StatStructure.st_mode) ) 00116 return true; 00117 00118 return false; 00119 00120 } 00121 00122 const bool compp::DirEntry::isBlockDevice () const { 00123 00124 if ( S_ISBLK (StatStructure.st_mode) ) 00125 return true; 00126 00127 return false; 00128 00129 } 00130 00131 const bool compp::DirEntry::isFIFO () const { 00132 00133 if ( S_ISFIFO (StatStructure.st_mode) ) 00134 return true; 00135 00136 return false; 00137 00138 } 00139 00140 const bool compp::DirEntry::isSocket () const { 00141 #ifdef S_ISSOCK 00142 00143 if ( S_ISSOCK (StatStructure.st_mode) ) 00144 return true; 00145 return false; 00146 00147 #else 00148 return false; 00149 #endif 00150 } 00151 00152 00153 const bool compp::DirEntry::isSymLink () const { 00154 #ifdef S_ISLNK 00155 if ( S_ISLNK (StatStructure.st_mode) ) 00156 return true; 00157 00158 return false; 00159 #else 00160 return false; 00161 #endif 00162 00163 00164 } 00165 00166 bool compp::DirEntry::Exist ( const std::string & Path ) { 00167 00168 struct stat Ss; 00169 00170 if ( 0 == stat( Path.c_str(), & Ss) ) 00171 return true; 00172 00173 return false; 00174 00175 } 00176 00177 00178 const std::string compp::DirEntry::getName () const { 00179 00180 return Name; 00181 00182 } 00183 00184 const int compp::DirEntry::getInode () const { 00185 00186 return StatStructure.st_ino; 00187 00188 } 00189 00190 const int compp::DirEntry::getAccessTime() const { 00191 00192 return StatStructure.st_atime; 00193 00194 } 00195 00196 const int compp::DirEntry::getChangeTime() const { 00197 00198 return StatStructure.st_ctime; 00199 00200 } 00201 00202 const int compp::DirEntry::getLastModificationTime() const { 00203 00204 return StatStructure.st_mtime; 00205 00206 } 00207 00208 const int compp::DirEntry::getSize() const { 00209 00210 return StatStructure.st_size; 00211 00212 } 00213 00214 const int compp::DirEntry::getUid() const { 00215 00216 return StatStructure.st_uid; 00217 00218 } 00219 00220 const int compp::DirEntry::getGid() const { 00221 00222 return StatStructure.st_gid; 00223 00224 } 00225 00226 00227 const int compp::DirEntry::getNumLinks() const { 00228 00229 return StatStructure.st_nlink; 00230 00231 } 00232 00233 00234 compp::File *compp::DirEntry::getFile () { 00235 00236 return new File ( this->Name ); 00237 00238 } 00239
1.6.3