Last change
on this file since 360 was
360,
checked in by Jari Häkkinen, 18 years ago
|
Added function to check file existence.
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
File size:
1.2 KB
|
Line | |
---|
1 | // $Id: FileIO.h 360 2005-08-04 19:41:02Z jari $ |
---|
2 | |
---|
3 | #ifndef _theplu_utility_fileio_ |
---|
4 | #define _theplu_utility_fileio_ |
---|
5 | |
---|
6 | #include <string> |
---|
7 | |
---|
8 | #include <unistd.h> |
---|
9 | |
---|
10 | namespace theplu { |
---|
11 | namespace utility { |
---|
12 | |
---|
13 | /// |
---|
14 | /// FileIO is useful for many common task on files. |
---|
15 | /// |
---|
16 | class FileIO { |
---|
17 | public: |
---|
18 | |
---|
19 | /// |
---|
20 | /// Check if access permissions match \a mode. \a mode must be |
---|
21 | /// given as r, w, x, or combinations of these letters. |
---|
22 | /// |
---|
23 | /// @return On success (all requested permissions granted), zero |
---|
24 | /// is returned. On error (at least one bit in mode asked for a |
---|
25 | /// permission that is denied, or some other error occurred), -1 |
---|
26 | /// is returned, and errno is set appropriately. |
---|
27 | /// |
---|
28 | /// @see access(2) |
---|
29 | /// |
---|
30 | /// @note Checking for write permissions will fail if the file |
---|
31 | /// does not exists. This should be fixed so that when a file does |
---|
32 | /// not exist, permissions to create the file should be returned. |
---|
33 | /// |
---|
34 | int access_rights(const std::string& path,const std::string& bits) const; |
---|
35 | |
---|
36 | /// |
---|
37 | /// Check whether \a file exists. |
---|
38 | /// |
---|
39 | /// @return True if \a file exists, false otherwise. |
---|
40 | /// |
---|
41 | /// @see access(2) |
---|
42 | /// |
---|
43 | inline bool file_exists(const std::string& file) const |
---|
44 | { return !access(file.c_str(),F_OK); } |
---|
45 | }; |
---|
46 | |
---|
47 | }} // of namespace utility and namespace theplu |
---|
48 | |
---|
49 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.