Release
[hcoop/zz_old/debian/suphp.git] / src / File.cpp
CommitLineData
623e7ab4 1/*
2 suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
3
4 This file is part of suPHP.
5
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include "API_Helper.hpp"
22
23#include "File.hpp"
24
25using namespace suPHP;
26
27bool suPHP::File::hasPermissionBit(FileMode perm) const throw (SystemException) {
28 return API_Helper::getSystemAPI().File_hasPermissionBit(*this, perm);
29}
30
31suPHP::File::File(std::string path) {
32 this->path = path;
33}
34
35std::string suPHP::File::getPath() const{
36 return this->path;
37}
38
39SmartPtr<std::ifstream> suPHP::File::getInputStream() const throw (IOException) {
40 std::ifstream* infile = new std::ifstream();
41 infile->open(this->path.c_str());
42 if (infile->bad() || infile->fail()) {
43 throw IOException("Could not open file " +
44 this->path + " for reading", __FILE__, __LINE__);
45 }
46 return SmartPtr<std::ifstream>(infile);
47}
48
49bool suPHP::File::exists() const {
50 return API_Helper::getSystemAPI().File_exists(*this);
51}
52
53std::string suPHP::File::getRealPath() const throw (SystemException) {
54 return API_Helper::getSystemAPI().File_getRealPath(*this);
55}
56
57File suPHP::File::getParentDirectory() const {
58 std::string path = this->getPath();
59 path = path.substr(0, path.rfind('/'));
60 if (path.length() == 0) {
61 path = "/";
62 }
63 return File(path);
64}
65
66bool suPHP::File::hasUserReadBit() const throw (SystemException) {
67 return this->hasPermissionBit(FILEMODE_USER_READ);
68}
69
70bool suPHP::File::hasUserWriteBit() const throw (SystemException) {
71 return this->hasPermissionBit(FILEMODE_USER_WRITE);
72}
73
74bool suPHP::File::hasUserExecuteBit() const throw (SystemException) {
75 return this->hasPermissionBit(FILEMODE_USER_EXEC);
76}
77
78bool suPHP::File::hasGroupReadBit() const throw (SystemException) {
79 return this->hasPermissionBit(FILEMODE_GROUP_READ);
80}
81
82bool suPHP::File::hasGroupWriteBit() const throw (SystemException) {
83 return this->hasPermissionBit(FILEMODE_GROUP_WRITE);
84}
85
86bool suPHP::File::hasGroupExecuteBit() const throw (SystemException) {
87 return this->hasPermissionBit(FILEMODE_GROUP_EXEC);
88}
89
90bool suPHP::File::hasOthersReadBit() const throw (SystemException) {
91 return this->hasPermissionBit(FILEMODE_OTHERS_READ);
92}
93
94bool suPHP::File::hasOthersWriteBit() const throw (SystemException) {
95 return this->hasPermissionBit(FILEMODE_OTHERS_WRITE);
96}
97
98bool suPHP::File::hasOthersExecuteBit() const throw (SystemException) {
99 return this->hasPermissionBit(FILEMODE_OTHERS_EXEC);
100}
101
102
103UserInfo suPHP::File::getUser() const throw (SystemException) {
104 return API_Helper::getSystemAPI().File_getUser(*this);
105}
106
107GroupInfo suPHP::File::getGroup() const throw (SystemException) {
108 return API_Helper::getSystemAPI().File_getGroup(*this);
109}
110
111
112bool suPHP::File::isSymlink() const throw (SystemException) {
113 return API_Helper::getSystemAPI().File_isSymlink(*this);
114}