00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_file_stat_h)
00024 #define octave_file_stat_h 1
00025
00026 #include <string>
00027
00028 #include "oct-time.h"
00029
00030 #ifdef HAVE_SYS_TYPES_H
00031 #include <sys/types.h>
00032 #endif
00033
00034 class
00035 file_stat
00036 {
00037 public:
00038
00039 file_stat (const std::string& n = std::string (), bool fl = true)
00040 : file_name (n), follow_links (fl), initialized (false)
00041 {
00042 if (! file_name.empty ())
00043 update_internal ();
00044 }
00045
00046 file_stat (const file_stat& f) { copy (f); }
00047
00048 file_stat& operator = (const file_stat& f)
00049 {
00050 if (this != &f)
00051 copy (f);
00052
00053 return *this;
00054 }
00055
00056 ~file_stat (void) { }
00057
00058 void get_stats (bool force = false)
00059 {
00060 if (! initialized || force)
00061 update_internal (force);
00062 }
00063
00064 void get_stats (const std::string& n, bool force = false)
00065 {
00066 if (n != file_name || ! initialized || force)
00067 {
00068 initialized = false;
00069
00070 file_name = n;
00071
00072 update_internal (force);
00073 }
00074 }
00075
00076
00077
00078
00079 bool is_blk (void) const;
00080 bool is_chr (void) const;
00081 bool is_dir (void) const;
00082 bool is_fifo (void) const;
00083 bool is_lnk (void) const;
00084 bool is_reg (void) const;
00085 bool is_sock (void) const;
00086
00087 ino_t ino (void) const { return fs_ino; }
00088 dev_t dev (void) const { return fs_dev; }
00089
00090 nlink_t nlink (void) const { return fs_nlink; }
00091
00092 uid_t uid (void) const { return fs_uid; }
00093 gid_t gid (void) const { return fs_gid; }
00094
00095 off_t size (void) const { return fs_size; }
00096
00097 octave_time atime (void) const { return fs_atime; }
00098 octave_time mtime (void) const { return fs_mtime; }
00099 octave_time ctime (void) const { return fs_ctime; }
00100
00101 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00102 dev_t rdev (void) const { return fs_rdev; }
00103 #endif
00104
00105 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00106 long blksize (void) const { return fs_blksize; }
00107 #endif
00108
00109 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00110 long blocks (void) const { return fs_blocks; }
00111 #endif
00112
00113 std::string mode_as_string (void) const;
00114
00115 bool ok (void) const { return initialized && ! fail; }
00116
00117 operator bool () const { return ok (); }
00118
00119 bool exists (void) const { return ok (); }
00120
00121 std::string error (void) const { return ok () ? std::string () : errmsg; }
00122
00123
00124 bool is_newer (const octave_time& time) const { return fs_mtime > time; }
00125
00126
00127
00128 static int is_newer (const std::string&, const octave_time&);
00129
00130 private:
00131
00132
00133 std::string file_name;
00134
00135
00136
00137 bool follow_links;
00138
00139
00140 bool initialized;
00141
00142
00143 bool fail;
00144
00145
00146 std::string errmsg;
00147
00148
00149 mode_t fs_mode;
00150
00151
00152 ino_t fs_ino;
00153
00154
00155 dev_t fs_dev;
00156
00157
00158 nlink_t fs_nlink;
00159
00160
00161 uid_t fs_uid;
00162
00163
00164 gid_t fs_gid;
00165
00166
00167 off_t fs_size;
00168
00169
00170 octave_time fs_atime;
00171
00172
00173 octave_time fs_mtime;
00174
00175
00176 octave_time fs_ctime;
00177
00178 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00179
00180 dev_t fs_rdev;
00181 #endif
00182
00183 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00184
00185 long fs_blksize;
00186 #endif
00187
00188 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00189
00190 long fs_blocks;
00191 #endif
00192
00193 void update_internal (bool force = false);
00194
00195 void copy (const file_stat&);
00196 };
00197
00198 #endif
00199
00200
00201
00202
00203
00204