69 |
11 Feb 06 |
jari |
// $Id$ |
69 |
11 Feb 06 |
jari |
2 |
|
95 |
05 Apr 06 |
jari |
3 |
/* |
95 |
05 Apr 06 |
jari |
Copyright (C) 2004 Jari Häkkinen |
95 |
05 Apr 06 |
jari |
Copyright (C) 2005 Peter Johansson |
95 |
05 Apr 06 |
jari |
Copyright (C) 2006 Jari Häkkinen |
95 |
05 Apr 06 |
jari |
7 |
|
95 |
05 Apr 06 |
jari |
This file is part of the thep c++ tools library, |
95 |
05 Apr 06 |
jari |
http://lev.thep.lu.se/trac/c++_tools |
95 |
05 Apr 06 |
jari |
10 |
|
95 |
05 Apr 06 |
jari |
The c++ tools library is free software; you can redistribute it |
95 |
05 Apr 06 |
jari |
and/or modify it under the terms of the GNU General Public License |
824 |
26 Nov 08 |
jari |
as published by the Free Software Foundation; either version 3 of |
95 |
05 Apr 06 |
jari |
the License, or (at your option) any later version. |
95 |
05 Apr 06 |
jari |
15 |
|
95 |
05 Apr 06 |
jari |
The c++ tools library is distributed in the hope that it will be |
95 |
05 Apr 06 |
jari |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
95 |
05 Apr 06 |
jari |
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
95 |
05 Apr 06 |
jari |
General Public License for more details. |
95 |
05 Apr 06 |
jari |
20 |
|
95 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
824 |
26 Nov 08 |
jari |
along with WeNNI. If not, see <http://www.gnu.org/licenses/>. |
95 |
05 Apr 06 |
jari |
23 |
*/ |
95 |
05 Apr 06 |
jari |
24 |
|
69 |
11 Feb 06 |
jari |
25 |
#ifndef _theplu_utility_fileio_ |
69 |
11 Feb 06 |
jari |
26 |
#define _theplu_utility_fileio_ |
69 |
11 Feb 06 |
jari |
27 |
|
69 |
11 Feb 06 |
jari |
28 |
#include <string> |
69 |
11 Feb 06 |
jari |
29 |
|
69 |
11 Feb 06 |
jari |
30 |
#include <unistd.h> |
69 |
11 Feb 06 |
jari |
31 |
|
69 |
11 Feb 06 |
jari |
32 |
namespace theplu { |
69 |
11 Feb 06 |
jari |
33 |
namespace utility { |
69 |
11 Feb 06 |
jari |
34 |
|
69 |
11 Feb 06 |
jari |
35 |
/// |
69 |
11 Feb 06 |
jari |
/// FileIO is useful for many common task on files. |
69 |
11 Feb 06 |
jari |
37 |
/// |
69 |
11 Feb 06 |
jari |
38 |
class FileIO { |
69 |
11 Feb 06 |
jari |
39 |
public: |
69 |
11 Feb 06 |
jari |
40 |
|
69 |
11 Feb 06 |
jari |
41 |
/// |
69 |
11 Feb 06 |
jari |
/// Check if access permissions match \a mode. \a mode must be |
69 |
11 Feb 06 |
jari |
/// given as r, w, x, or combinations of these letters. |
69 |
11 Feb 06 |
jari |
44 |
/// |
69 |
11 Feb 06 |
jari |
/// @return On success (all requested permissions granted), zero |
69 |
11 Feb 06 |
jari |
/// is returned. On error (at least one bit in mode asked for a |
69 |
11 Feb 06 |
jari |
/// permission that is denied, or some other error occurred), -1 |
69 |
11 Feb 06 |
jari |
/// is returned, and errno is set appropriately. |
69 |
11 Feb 06 |
jari |
49 |
/// |
69 |
11 Feb 06 |
jari |
/// @see access(2) |
69 |
11 Feb 06 |
jari |
51 |
/// |
69 |
11 Feb 06 |
jari |
/// @note Checking for write permissions will fail if the file |
69 |
11 Feb 06 |
jari |
/// does not exists. This should be fixed so that when a file does |
69 |
11 Feb 06 |
jari |
/// not exist, permissions to create the file should be returned. |
69 |
11 Feb 06 |
jari |
55 |
/// |
69 |
11 Feb 06 |
jari |
56 |
int access_rights(const std::string& path,const std::string& bits) const; |
69 |
11 Feb 06 |
jari |
57 |
|
69 |
11 Feb 06 |
jari |
58 |
/// |
69 |
11 Feb 06 |
jari |
/// Check whether \a file exists. |
69 |
11 Feb 06 |
jari |
60 |
/// |
69 |
11 Feb 06 |
jari |
/// @return True if \a file exists, false otherwise. |
69 |
11 Feb 06 |
jari |
62 |
/// |
69 |
11 Feb 06 |
jari |
/// @see access(2) |
69 |
11 Feb 06 |
jari |
64 |
/// |
69 |
11 Feb 06 |
jari |
65 |
inline bool file_exists(const std::string& file) const |
69 |
11 Feb 06 |
jari |
66 |
{ return !access(file.c_str(),F_OK); } |
69 |
11 Feb 06 |
jari |
67 |
}; |
69 |
11 Feb 06 |
jari |
68 |
|
69 |
11 Feb 06 |
jari |
69 |
}} // of namespace utility and namespace theplu |
69 |
11 Feb 06 |
jari |
70 |
|
69 |
11 Feb 06 |
jari |
71 |
#endif |