00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef FILEINFO_H
00021 #define FILEINFO_H
00022
00023 #include <sys/stat.h>
00024 #include <string>
00025
00026 #ifdef _WIN32
00027 #ifndef nlink_t
00028 typedef unsigned short int nlink_t;
00029 #endif
00030 #ifndef uid_t
00031 typedef unsigned int uid_t;
00032 #endif
00033 #ifndef gid_t
00034 typedef unsigned int gid_t;
00035 #endif
00036 #ifndef blkcnt_t
00037 typedef unsigned long int blkcnt_t;
00038 #endif
00039 #endif
00040
00041 using std::string;
00042
00044
00064 class FileInfo
00065 {
00066
00067 public:
00069 FileInfo() : mValid(false) {}
00070 FileInfo(const string & filename);
00071 ~FileInfo() {};
00072
00073 off_t size() const {return mStat.st_size;}
00074 time_t atime() const {return mStat.st_atime;}
00075 time_t mtime() const {return mStat.st_mtime;}
00076 time_t ctime() const {return mStat.st_ctime;}
00077 mode_t mode() const {return mStat.st_mode;}
00078 ino_t inode() const {return mStat.st_ino;}
00079 dev_t device() const {return mStat.st_dev;}
00080 #ifdef _WIN32
00081 nlink_t nlinks() const {return 0;}
00082 uid_t uid() const {return 0;}
00083 gid_t gid() const {return 0;}
00084
00085
00086
00087 blkcnt_t blocks() const {return 0;}
00088 unsigned int optblocksize() const {return 512;}
00090 bool isLink() const {return false;}
00091 #else
00092 nlink_t nlinks() const {return mStat.st_nlink;}
00093 uid_t uid() const {return mStat.st_uid;}
00094 gid_t gid() const {return mStat.st_gid;}
00095
00096
00097
00098 blkcnt_t blocks() const {return mStat.st_blocks;}
00099 unsigned int optblocksize() const {return mStat.st_blksize;}
00101 bool isLink() const {return S_ISLNK (mStat.st_mode) ? true : false;}
00102 #endif
00103 bool isDir() const {return S_ISDIR(mStat.st_mode) ? true : false;}
00104 bool isFile() const {return S_ISDIR(mStat.st_mode) ? false : true;}
00105
00106 bool isValid() {return mValid;}
00107
00108 bool read(const string & fname, bool followlink=false);
00109
00110 private:
00111 struct stat mStat;
00112 bool mValid;
00113
00114 };
00115
00116
00117 #endif
00118