ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
fileinfo.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Fred Klaus *
3  * frednet@web.de *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef FILEINFO_H
21 #define FILEINFO_H
22 
23 #include <sys/stat.h>
24 #include <string>
25 
26 #if defined(_WIN32) || defined(_WIN64)
27  #ifndef nlink_t
28  typedef unsigned short int nlink_t;
29  #endif
30  #ifndef uid_t
31  typedef unsigned int uid_t;
32  #endif
33  #ifndef gid_t
34  typedef unsigned int gid_t;
35  #endif
36  #ifndef blkcnt_t
37  typedef unsigned long int blkcnt_t;
38  #endif
39 #endif
40 
41 using std::string;
42 
44 
64 class FileInfo
65 {
66 
67 public:
69  FileInfo() : mValid(false) {}
70  FileInfo(const string & filename);
71  ~FileInfo() {};
72 
73  off_t size() const {return mStat.st_size;}
74  time_t atime() const {return mStat.st_atime;}
75  time_t mtime() const {return mStat.st_mtime;}
76  time_t ctime() const {return mStat.st_ctime;}
77  ino_t inode() const {return mStat.st_ino;}
78  dev_t device() const {return mStat.st_dev;}
79 #if defined(_WIN32) || defined(_WIN64)
80  #ifndef S_ISDIR
81  #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
82  #endif
83  //mode_t mode() const {return mStat.st_mode;}
84  nlink_t nlinks() const {return 0;}
85  uid_t uid() const {return 0;}
86  gid_t gid() const {return 0;}
87  //unsigned long int ausec() const {return mStat.st_atime_usec;}
88  //unsigned long int musec() const {return mStat.st_mtime_usec;}
89  //unsigned long int cusec() const {return mStat.st_ctime_usec;}
90  blkcnt_t blocks() const {return 0;}
91  unsigned int optblocksize() const {return 512;}
93  bool isLink() const {return false;}
94 #else
95  mode_t mode() const {return mStat.st_mode;}
96  nlink_t nlinks() const {return mStat.st_nlink;}
97  uid_t uid() const {return mStat.st_uid;}
98  gid_t gid() const {return mStat.st_gid;}
99  //unsigned long int ausec() const {return mStat.st_atime_usec;}
100  //unsigned long int musec() const {return mStat.st_mtime_usec;}
101  //unsigned long int cusec() const {return mStat.st_ctime_usec;}
102  blkcnt_t blocks() const {return mStat.st_blocks;}
103  unsigned int optblocksize() const {return mStat.st_blksize;}
105  bool isLink() const {return S_ISLNK (mStat.st_mode) ? true : false;}
106 #endif
107  bool isDir() const {return S_ISDIR(mStat.st_mode) ? true : false;}
108  bool isFile() const {return S_ISDIR(mStat.st_mode) ? false : true;}
109 
110  bool isValid() {return mValid;}
111 
112  bool read(const string & fname, bool followlink=false);
113 
114 private:
115  struct stat mStat;
116  bool mValid;
117 
118 };
119 
120 
121 #endif
122 
unsigned int optblocksize() const
Definition: fileinfo.h:103
time_t atime() const
Definition: fileinfo.h:74
uid_t uid() const
Definition: fileinfo.h:97
FileInfo()
Definition: fileinfo.h:69
nlink_t nlinks() const
Definition: fileinfo.h:96
#define S_ISDIR(mode)
Definition: windirent.h:188
ino_t inode() const
Definition: fileinfo.h:77
blkcnt_t blocks() const
Definition: fileinfo.h:102
bool read(const string &fname, bool followlink=false)
Definition: fileinfo.cpp:24
mode_t mode() const
Definition: fileinfo.h:95
gid_t gid() const
Definition: fileinfo.h:98
bool isValid()
Definition: fileinfo.h:110
bool mValid
Definition: fileinfo.h:116
bool isFile() const
Definition: fileinfo.h:108
time_t mtime() const
Definition: fileinfo.h:75
time_t ctime() const
Definition: fileinfo.h:76
bool isDir() const
Definition: fileinfo.h:107
off_t size() const
Definition: fileinfo.h:73
~FileInfo()
Definition: fileinfo.h:71
struct stat mStat
Definition: fileinfo.h:115
dev_t device() const
Definition: fileinfo.h:78
#define S_ISLNK(mode)
Definition: windirent.h:194
bool isLink() const
Definition: fileinfo.h:105
Represents Fileattributes.
Definition: fileinfo.h:64