Mercurial > octave
annotate liboctave/system/file-stat.h @ 21017:93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
* Backend.cc, comment-list.h, debug.cc, defaults.in.h, dynamic-ld.h, error.cc,
graphics.cc, graphics.in.h, help.cc, hook-fcn.h, load-path.cc, load-path.h,
ls-ascii-helper.cc, ls-mat-ascii.cc, ls-mat5.cc, ls-mat5.h, ls-oct-text.cc,
oct-iostrm.h, oct-lvalue.h, oct-stream.cc, oct-stream.h, oct-strstrm.h,
regexp.cc, schur.cc, sqrtm.cc, strfns.cc, symtab.cc, symtab.h, sysdep.cc,
toplev.cc, urlwrite.cc, variables.cc, variables.h, ov-builtin.h, ov-cell.cc,
ov-class.cc, ov-classdef.cc, ov-classdef.h, ov-dld-fcn.h, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.h, ov-lazy-idx.cc, ov-mex-fcn.h,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.h,
ovl.h, octave.cc, lex.h, parse.h, pt-classdef.h, pt-exp.cc, pt-pr-code.h,
token.h, version.cc, version.in.h, oct-rand.h, dir-ops.h, file-ops.cc,
file-ops.h, file-stat.h, oct-env.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, kpse.cc,
lo-array-gripes.h, pathsearch.cc, pathsearch.h, str-vec.h, url-transfer.h:
Replace emtpy 'std::string ()' calls with "".
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Dec 2015 12:33:33 -0800 |
parents | d0991cbd6141 |
children | 1473547f50f5 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2926 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2926 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2926 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_file_stat_h) |
2926 | 24 #define octave_file_stat_h 1 |
25 | |
26 #include <string> | |
27 | |
3260 | 28 #include "oct-time.h" |
29 | |
2926 | 30 #include <sys/types.h> |
31 | |
32 class | |
6108 | 33 OCTAVE_API |
8549 | 34 base_file_stat |
2926 | 35 { |
36 public: | |
37 | |
8549 | 38 base_file_stat (void) |
39 : initialized (false), fail (false), errmsg (), fs_mode (), | |
40 fs_ino (), fs_dev (), fs_nlink (), fs_uid (), fs_gid (), | |
41 fs_size (), fs_atime (), fs_mtime (), fs_ctime (), fs_rdev (), | |
42 fs_blksize (), fs_blocks () { } | |
43 | |
44 base_file_stat (const base_file_stat& fs) | |
45 : initialized (fs.initialized), fail (fs.fail), errmsg (fs.errmsg), | |
46 fs_mode (fs.fs_mode), fs_ino (fs.fs_ino), fs_dev (fs.fs_dev), | |
47 fs_nlink (fs.fs_nlink), fs_uid (fs.fs_uid), fs_gid (fs.fs_gid), | |
48 fs_size (fs.fs_size), fs_atime (fs.fs_atime), fs_mtime (fs.fs_mtime), | |
49 fs_ctime (fs.fs_ctime), fs_rdev (fs.fs_rdev), | |
50 fs_blksize (fs.fs_blksize), fs_blocks (fs.fs_blocks) { } | |
51 | |
52 base_file_stat& operator = (const base_file_stat& fs) | |
53 { | |
54 if (this != &fs) | |
2926 | 55 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
56 initialized = fs.initialized; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
57 fail = fs.fail; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
58 errmsg = fs.errmsg; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
59 fs_mode = fs.fs_mode; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
60 fs_ino = fs.fs_ino; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
61 fs_dev = fs.fs_dev; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
62 fs_nlink = fs.fs_nlink; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
63 fs_uid = fs.fs_uid; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
64 fs_gid = fs.fs_gid; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
65 fs_size = fs.fs_size; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
66 fs_atime = fs.fs_atime; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
67 fs_mtime = fs.fs_mtime; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
68 fs_ctime = fs.fs_ctime; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
69 fs_rdev = fs.fs_rdev; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
70 fs_blksize = fs.fs_blksize; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
71 fs_blocks = fs.fs_blocks; |
2926 | 72 } |
73 | |
8549 | 74 return *this; |
75 } | |
2926 | 76 |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 // The minimum difference in file time stamp values. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 // FIXME: This value should come from the filesystem itself. |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 // How can we get that info? |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
80 octave_time time_resolution (void) const |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
81 { |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
82 static octave_time resolution (1.0); |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
83 return resolution; |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
84 } |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
85 |
8689
ddbe87599331
base_file_stat::is_XXX: return false if object is not initialized
John W. Eaton <jwe@octave.org>
parents:
8549
diff
changeset
|
86 // File status and info. The is_XXX functions will return false for |
ddbe87599331
base_file_stat::is_XXX: return false if object is not initialized
John W. Eaton <jwe@octave.org>
parents:
8549
diff
changeset
|
87 // file_stat objects that are not properly initialized. The others |
ddbe87599331
base_file_stat::is_XXX: return false if object is not initialized
John W. Eaton <jwe@octave.org>
parents:
8549
diff
changeset
|
88 // should all return 0 (or the equivalent, for the given object) |
ddbe87599331
base_file_stat::is_XXX: return false if object is not initialized
John W. Eaton <jwe@octave.org>
parents:
8549
diff
changeset
|
89 // which is likely not meaningful. |
2926 | 90 |
91 bool is_blk (void) const; | |
92 bool is_chr (void) const; | |
93 bool is_dir (void) const; | |
94 bool is_fifo (void) const; | |
95 bool is_lnk (void) const; | |
96 bool is_reg (void) const; | |
97 bool is_sock (void) const; | |
98 | |
5476 | 99 static bool is_blk (mode_t mode); |
100 static bool is_chr (mode_t mode); | |
101 static bool is_dir (mode_t mode); | |
102 static bool is_fifo (mode_t mode); | |
103 static bool is_lnk (mode_t mode); | |
104 static bool is_reg (mode_t mode); | |
105 static bool is_sock (mode_t mode); | |
106 | |
2926 | 107 ino_t ino (void) const { return fs_ino; } |
108 dev_t dev (void) const { return fs_dev; } | |
109 | |
110 nlink_t nlink (void) const { return fs_nlink; } | |
111 | |
112 uid_t uid (void) const { return fs_uid; } | |
113 gid_t gid (void) const { return fs_gid; } | |
114 | |
115 off_t size (void) const { return fs_size; } | |
116 | |
3260 | 117 octave_time atime (void) const { return fs_atime; } |
118 octave_time mtime (void) const { return fs_mtime; } | |
119 octave_time ctime (void) const { return fs_ctime; } | |
2926 | 120 |
121 dev_t rdev (void) const { return fs_rdev; } | |
122 | |
123 long blksize (void) const { return fs_blksize; } | |
124 long blocks (void) const { return fs_blocks; } | |
125 | |
5476 | 126 mode_t mode (void) const { return fs_mode; } |
127 | |
3504 | 128 std::string mode_as_string (void) const; |
2926 | 129 |
130 bool ok (void) const { return initialized && ! fail; } | |
131 | |
3145 | 132 operator bool () const { return ok (); } |
2926 | 133 |
134 bool exists (void) const { return ok (); } | |
135 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20792
diff
changeset
|
136 std::string error (void) const { return ok () ? "" : errmsg; } |
2926 | 137 |
138 // Has the file referenced by this object been modified since TIME? | |
3260 | 139 bool is_newer (const octave_time& time) const { return fs_mtime > time; } |
2926 | 140 |
141 // It's nice to be able to hide the file_stat object if we don't | |
142 // really care about it. | |
3504 | 143 static int is_newer (const std::string&, const octave_time&); |
2926 | 144 |
8549 | 145 protected: |
2926 | 146 |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
147 virtual ~base_file_stat (void) { } |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
148 |
2926 | 149 // TRUE means we have already called stat. |
150 bool initialized; | |
151 | |
152 // TRUE means the stat for this file failed. | |
153 bool fail; | |
154 | |
155 // If a failure occurs, this contains the system error text. | |
3504 | 156 std::string errmsg; |
2926 | 157 |
158 // file type and permissions | |
159 mode_t fs_mode; | |
160 | |
161 // serial number | |
162 ino_t fs_ino; | |
163 | |
164 // device number | |
165 dev_t fs_dev; | |
166 | |
167 // number of links | |
168 nlink_t fs_nlink; | |
169 | |
170 // user ID of owner | |
171 uid_t fs_uid; | |
172 | |
173 // group ID of owner | |
174 gid_t fs_gid; | |
175 | |
176 // size in bytes, for regular files | |
177 off_t fs_size; | |
178 | |
179 // time of last access | |
3260 | 180 octave_time fs_atime; |
2926 | 181 |
182 // time of last modification | |
3260 | 183 octave_time fs_mtime; |
2926 | 184 |
185 // time of last file status change | |
3260 | 186 octave_time fs_ctime; |
2926 | 187 |
188 // device number for special files | |
189 dev_t fs_rdev; | |
190 | |
191 // best I/O block size | |
192 long fs_blksize; | |
193 | |
194 // number of 512-byte blocks allocated | |
195 long fs_blocks; | |
8549 | 196 }; |
197 | |
198 class | |
199 OCTAVE_API | |
200 file_stat : public base_file_stat | |
201 { | |
202 public: | |
203 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20792
diff
changeset
|
204 file_stat (const std::string& n = "", bool fl = true) |
8549 | 205 : base_file_stat (), file_name (n), follow_links (fl) |
206 { | |
207 if (! file_name.empty ()) | |
208 update_internal (); | |
209 } | |
210 | |
211 file_stat (const file_stat& fs) | |
212 : base_file_stat (fs), file_name (fs.file_name), | |
213 follow_links (fs.follow_links) { } | |
214 | |
215 file_stat& operator = (const file_stat& fs) | |
216 { | |
217 if (this != &fs) | |
218 { | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
219 base_file_stat::operator = (fs); |
8549 | 220 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
221 file_name = fs.file_name; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
222 follow_links = fs.follow_links; |
8549 | 223 } |
224 | |
225 return *this; | |
226 } | |
227 | |
228 ~file_stat (void) { } | |
229 | |
230 void get_stats (bool force = false) | |
231 { | |
232 if (! initialized || force) | |
233 update_internal (force); | |
234 } | |
235 | |
236 void get_stats (const std::string& n, bool force = false) | |
237 { | |
20792
d0991cbd6141
maint: Remove extra spaces in if () conditionals.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
238 if (n != file_name || ! initialized || force) |
8549 | 239 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
240 initialized = false; |
8549 | 241 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
242 file_name = n; |
8549 | 243 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
244 update_internal (force); |
8549 | 245 } |
246 } | |
247 | |
248 private: | |
249 | |
250 // Name of the file. | |
251 std::string file_name; | |
252 | |
253 // TRUE means follow symbolic links to the ultimate file (stat). | |
254 // FALSE means get information about the link itself (lstat). | |
255 bool follow_links; | |
2926 | 256 |
257 void update_internal (bool force = false); | |
8549 | 258 }; |
2926 | 259 |
8549 | 260 class |
261 OCTAVE_API | |
262 file_fstat : public base_file_stat | |
263 { | |
264 public: | |
265 | |
266 file_fstat (int n) : base_file_stat (), fid (n) | |
267 { | |
268 update_internal (); | |
269 } | |
270 | |
271 file_fstat (const file_fstat& fs) | |
272 : base_file_stat (fs), fid (fs.fid) { } | |
273 | |
274 file_fstat& operator = (const file_fstat& fs) | |
275 { | |
276 if (this != &fs) | |
277 { | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
278 base_file_stat::operator = (fs); |
8549 | 279 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
280 fid = fs.fid; |
8549 | 281 } |
282 | |
283 return *this; | |
284 } | |
285 | |
286 ~file_fstat (void) { } | |
287 | |
288 void get_stats (bool force = false) | |
289 { | |
290 if (! initialized || force) | |
291 update_internal (force); | |
292 } | |
293 | |
294 void get_stats (int n, bool force = false) | |
295 { | |
20792
d0991cbd6141
maint: Remove extra spaces in if () conditionals.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
296 if (n != fid || ! initialized || force) |
8549 | 297 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
298 initialized = false; |
8549 | 299 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
300 fid = n; |
8549 | 301 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
302 update_internal (force); |
8549 | 303 } |
304 } | |
305 | |
306 private: | |
307 | |
308 // Open file descriptor. | |
309 int fid; | |
310 | |
311 void update_internal (bool force = false); | |
2926 | 312 }; |
313 | |
314 #endif |