gfilestat.h

Go to the documentation of this file.
00001 #ifndef gFILESTAT_X_H
00002 #define gFILESTAT_X_H
00003 
00004 #include <stdio.h>
00005 #include <unistd.h>
00006 #include <sys/stat.h>       // For fstat, ...
00007 #include <sys/types.h>      // For off_t, ...
00008 #include "gstring.h"
00009 
00010 typedef t_uint16 t_fs_perm;
00011 ////////////////////////////////////////////////////////////
00012 struct sFileStat {
00013     sFileStat ()
00014         : inode( 0 ),
00015           mode( 0 ),
00016           uid( 0xFFFF ),
00017           gid( 0xFFFF ),
00018           size( 0 ),
00019           blocks( 0 ),
00020           nLinks( 0 ),
00021           aTime( 0 ),  // time of last access
00022           mTime( 0 ),  // time of last modification
00023           cTime( 0 ) { // time of last change
00024                        // cTime change: e.g. owner change
00025     }
00026     t_inode inode;
00027     t_uint32 mode;
00028     t_uint16 uid, gid;
00029     t_uint32 size;
00030     t_uint32 blocks;
00031     t_uint16 nLinks;
00032     time_t aTime, mTime, cTime;
00033 
00034     void ToDefault () {
00035         inode = 0;
00036         mode = 0;
00037         size = blocks = 0;
00038         nLinks = 0;
00039         uid = gid = 0xFFFF;
00040         aTime = mTime = cTime;
00041     }
00042 
00043     bool IsValid () {
00044         return uid!=0xFFFF && gid!=0xFFFF;
00045     }
00046 
00047     bool IsDirectory () ;
00048     bool IsLink () ;
00049 
00050     t_fs_perm Permission () ;
00051     t_fs_perm AllPermission () ;
00052 
00053     long Size () ;
00054     t_uint32 USize () ;
00055 
00056     void Copy (sFileStat& copy) {
00057         inode = copy.inode;
00058         mode = copy.mode;
00059         uid = copy.uid;
00060         gid = copy.gid;
00061         size = copy.size;
00062         blocks = copy.blocks;
00063         nLinks = copy.nLinks;
00064         aTime = copy.aTime;
00065         mTime = copy.mTime;
00066         cTime = copy.cTime;
00067     }
00068 };
00069 ////////////////////////////////////////////////////////////
00070 class gFileStat {
00071 public:
00072     gFileStat (char* fName=NULL) ;
00073     gFileStat (gString& sName) ;
00074     gFileStat (int fd) ;
00075     virtual ~gFileStat () ;
00076 
00077     // Public data-members
00078     int lastOpError, lastOpErrorL;
00079     gString name;
00080     sFileStat status, statusL;
00081 
00082     // Get methods
00083     virtual bool IsOk () {
00084         return HasStat()==true && Error()==0;
00085     }
00086 
00087     virtual bool HasStat () {
00088         return hasStat==true;
00089     }
00090 
00091     int Error () {
00092         return lastOpError==0 ? lastOpErrorL : lastOpError;
00093     }
00094 
00095     bool IsDirectory () {
00096         return statusL.IsDirectory();
00097     }
00098     bool IsLink () {
00099         return statusL.IsLink();
00100     }
00101 
00102     // Set methods
00103     bool Update (int fd=-1) ;
00104     bool Update (char* fName) ;
00105 
00106     gFileStat& CopyStat (gFileStat& copy) ;
00107 
00108 protected:
00109     // Protected methods
00110     int thisStatName (char* fName,
00111                       int fd,
00112                       sFileStat& st,
00113                       sFileStat& stL) ;
00114     int thisFileStat (int fd,
00115                       sFileStat& st,
00116                       sFileStat& stL) ;
00117 
00118 private:
00119     bool hasStat;
00120     int fHandle;
00121 
00122     // Operators,empty
00123     gFileStat (gFileStat& ) ; //empty
00124     gFileStat& operator= (gFileStat& ) ; //empty
00125 };
00126 ////////////////////////////////////////////////////////////
00127 #endif //gFILESTAT_X_H
00128 

Generated on Sat Aug 18 02:40:53 2007 for xpfweb_v2x lib by  doxygen 1.4.2