fileinfo.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Fred Klaus                                      *
00003  *   frednet@web.de                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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         //unsigned long int ausec() const {return mStat.st_atime_usec;}
00085         //unsigned long int musec() const {return mStat.st_mtime_usec;}
00086         //unsigned long int cusec() const {return mStat.st_ctime_usec;}
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         //unsigned long int ausec() const {return mStat.st_atime_usec;}
00096         //unsigned long int musec() const {return mStat.st_mtime_usec;}
00097         //unsigned long int cusec() const {return mStat.st_ctime_usec;}
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 

Generated on Fri Mar 16 21:30:28 2007 for roland.kdevelop by  doxygen 1.5.0