1 | #ifndef _theplu_yat_utility_fileio_ |
---|
2 | #define _theplu_yat_utility_fileio_ |
---|
3 | |
---|
4 | // $Id: FileIO.h 687 2006-10-16 23:51:10Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Jari Häkkinen |
---|
8 | Copyright (C) 2005 Peter Johansson |
---|
9 | Copyright (C) 2006 Jari Häkkinen |
---|
10 | |
---|
11 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
12 | |
---|
13 | The yat library is free software; you can redistribute it and/or |
---|
14 | modify it under the terms of the GNU General Public License as |
---|
15 | published by the Free Software Foundation; either version 2 of the |
---|
16 | License, or (at your option) any later version. |
---|
17 | |
---|
18 | The yat library is distributed in the hope that it will be useful, |
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | General Public License for more details. |
---|
22 | |
---|
23 | You should have received a copy of the GNU General Public License |
---|
24 | along with this program; if not, write to the Free Software |
---|
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
26 | 02111-1307, USA. |
---|
27 | */ |
---|
28 | |
---|
29 | #include <string> |
---|
30 | |
---|
31 | #include <unistd.h> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace utility { |
---|
36 | |
---|
37 | /// |
---|
38 | /// FileIO is useful for many common task on files. |
---|
39 | /// |
---|
40 | class FileIO { |
---|
41 | public: |
---|
42 | |
---|
43 | /// |
---|
44 | /// Check if access permissions match \a mode. \a mode must be |
---|
45 | /// given as r, w, x, or combinations of these letters. |
---|
46 | /// |
---|
47 | /// @return On success (all requested permissions granted), zero |
---|
48 | /// is returned. On error (at least one bit in mode asked for a |
---|
49 | /// permission that is denied, or some other error occurred), -1 |
---|
50 | /// is returned, and errno is set appropriately. |
---|
51 | /// |
---|
52 | /// @see access(2) |
---|
53 | /// |
---|
54 | /// @note Checking for write permissions will fail if the file |
---|
55 | /// does not exists. This should be fixed so that when a file does |
---|
56 | /// not exist, permissions to create the file should be returned. |
---|
57 | /// |
---|
58 | int access_rights(const std::string& path,const std::string& bits) const; |
---|
59 | |
---|
60 | /// |
---|
61 | /// Check whether \a file exists. |
---|
62 | /// |
---|
63 | /// @return True if \a file exists, false otherwise. |
---|
64 | /// |
---|
65 | /// @see access(2) |
---|
66 | /// |
---|
67 | /// @todo Probably stat(2) should be used in favour of |
---|
68 | /// access(2). Change the implementation. |
---|
69 | /// |
---|
70 | inline bool file_exists(const std::string& file) const |
---|
71 | { return !access(file.c_str(),F_OK); } |
---|
72 | }; |
---|
73 | |
---|
74 | }}} // of namespace utility, yat, and theplu |
---|
75 | |
---|
76 | #endif |
---|