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 |
#include <c++_tools/utility/FileIO.h> |
69 |
11 Feb 06 |
jari |
26 |
|
69 |
11 Feb 06 |
jari |
27 |
#include <iostream> |
69 |
11 Feb 06 |
jari |
28 |
#include <unistd.h> |
69 |
11 Feb 06 |
jari |
29 |
|
69 |
11 Feb 06 |
jari |
30 |
|
69 |
11 Feb 06 |
jari |
31 |
namespace theplu { |
69 |
11 Feb 06 |
jari |
32 |
namespace utility { |
69 |
11 Feb 06 |
jari |
33 |
|
69 |
11 Feb 06 |
jari |
34 |
int FileIO::access_rights(const std::string& path, |
69 |
11 Feb 06 |
jari |
35 |
const std::string& bits) const { |
69 |
11 Feb 06 |
jari |
36 |
if (int value=access(path.c_str(),F_OK)) { |
69 |
11 Feb 06 |
jari |
37 |
std::cerr << "access_rights: File '" << path << "' does not exist." |
69 |
11 Feb 06 |
jari |
38 |
<< std::endl; |
69 |
11 Feb 06 |
jari |
39 |
return value; |
69 |
11 Feb 06 |
jari |
40 |
} |
69 |
11 Feb 06 |
jari |
41 |
int mode=0; |
819 |
24 Nov 08 |
jari |
42 |
for (unsigned int i=0; i<bits.length(); i++) |
69 |
11 Feb 06 |
jari |
43 |
switch (bits[i]) { |
69 |
11 Feb 06 |
jari |
44 |
case 'r': |
69 |
11 Feb 06 |
jari |
45 |
mode|=R_OK; |
69 |
11 Feb 06 |
jari |
46 |
break; |
69 |
11 Feb 06 |
jari |
47 |
case 'w': |
69 |
11 Feb 06 |
jari |
48 |
mode|=W_OK; |
69 |
11 Feb 06 |
jari |
49 |
break; |
69 |
11 Feb 06 |
jari |
50 |
case 'x': |
69 |
11 Feb 06 |
jari |
51 |
mode|=X_OK; |
69 |
11 Feb 06 |
jari |
52 |
break; |
69 |
11 Feb 06 |
jari |
53 |
} |
69 |
11 Feb 06 |
jari |
54 |
return access(path.c_str(),mode); |
69 |
11 Feb 06 |
jari |
55 |
} |
69 |
11 Feb 06 |
jari |
56 |
|
69 |
11 Feb 06 |
jari |
57 |
}} // of namespace utility and namespace theplu |