00001
00002
00003
00004
00005
00006
00007 #include <sys/types.h>
00008 #include "ComPlusPlus/File.h"
00009 #include "SysPlusPlus/syscall.h"
00010 #include "SysPlusPlus/ComException.h"
00011 #include <sys/stat.h>
00012 #include <fcntl.h>
00013
00014
00018 compp::File::~File () {
00019
00020
00021 }
00022
00026 compp::File::File ( ) {
00027
00028 SetName ( "" );
00029
00030 }
00031
00035 compp::File::File (const std::string & FileName) {
00036
00037 SetName ( FileName );
00038 OpenRW();
00039
00040 }
00044 void compp::File::SetName (const std::string & FileName){
00045 FN = FileName;
00046 }
00047 void compp::File::OpenWR(){
00048
00049 if ( fd != -1 )
00050 Close();
00051
00052 fd = syspp::Call::Open ( FN.c_str(), O_WRONLY|O_CREAT, 0644 ) ;
00053 if ( fd == -1 )
00054 throw syspp::ComException ( "Cannot open file" ) ;
00055 IsOpen = true;
00056 }
00057 void compp::File::OpenRD(){
00058
00059 if ( fd != -1 )
00060 Close();
00061
00062 fd = syspp::Call::Open ( FN.c_str(), O_RDONLY ) ;
00063 if ( fd == -1 )
00064 throw syspp::ComException ( "Cannot open file" ) ;
00065 IsOpen = true;
00066
00067 }
00068 void compp::File::OpenRW(){
00069
00070 if ( fd != -1 )
00071 Close();
00072
00073 fd = syspp::Call::Open ( FN.c_str(), O_RDONLY|O_WRONLY|O_CREAT, 0644 ) ;
00074 if ( fd == -1 )
00075 throw syspp::ComException ( "Cannot open file" ) ;
00076
00077 IsOpen = true;
00078 }
00079
00083 void compp::File::Truncate(){
00084
00085 if ( fd != -1 )
00086 Close();
00087
00088 fd = syspp::Call::Open ( FN.c_str(), O_RDONLY|O_WRONLY|O_CREAT|O_TRUNC, 0644 ) ;
00089 if ( fd == -1 )
00090 throw syspp::ComException ( "Cannot open file" ) ;
00091
00092 }
00093
00097 void compp::File::Create (){
00098
00099 if ( fd != -1 )
00100 Close();
00101
00102 fd = syspp::Call::Open ( FN.c_str(), O_RDONLY|O_WRONLY|O_CREAT, 0644 ) ;
00103 if ( fd == -1 )
00104 throw syspp::ComException ( "Cannot open file" ) ;
00105
00106 IsOpen = true;
00107 }
00108
00112 void compp::File::Lock (){
00113 }
00114
00118 void compp::File::UnLock (){
00119 }
00120
00121
00125 void compp::File::Delete (){
00126 syspp::Call::Unlink (FN.c_str());
00127 }
00128 void compp::File::Chmod (mode_t mode){
00129
00130 if ( fd == -1 ) {
00131 if ( FN != "" ) {
00132 if ( -1 == syspp::Call::Chmod ( FN.c_str(), mode ) ) {
00133 throw syspp::ComException ( "Cannot chmod" ) ;
00134 }
00135 }
00136 } else {
00137 if ( -1 == syspp::Call::FChmod ( fd , mode ) ) {
00138 throw syspp::ComException ( "Cannot chmod" ) ;
00139 }
00140 }
00141
00142 }
00143
00144
00148 void compp::File::SetPerm (){
00149 }
00150
00151
00155 void compp::File::SetOwnerRD (){
00156
00157 Chmod ( 0 );
00158
00159 }
00160
00164 void compp::File::SetOwnerWR (){
00165 }
00166
00170 void compp::File::SetOwnerRW (){
00171 }
00172
00181 void compp::File::SetGroupRD (){
00182 }
00183
00187 void compp::File::SetGroupWR (){
00188 }
00189
00193 void compp::File::SetGroupRW (){
00194 }
00195
00200 void compp::File::SetOthersRD (){
00201 }
00202
00206 void compp::File::SetOthersWR (){
00207 }
00208
00212 void compp::File::SetOthersRW (){
00213 }
00214
00215
00216
00220 bool compp::File::Exist ( const std::string & FileName ){
00221 return false;
00222 }
00223
00227 bool compp::File::IsWriteable ( const std::string & FileName ){
00228 return false;
00229 }
00230
00234 bool compp::File::IsReadable ( const std::string & FileName ){
00235 return false;
00236 }
00237
00241 void compp::File::SetOwnerRD ( const std::string & FileName ){
00242 }
00243
00247 void compp::File::SetOwnerWR ( const std::string & FileName ){
00248 }
00249
00253 void compp::File::SetOwnerRW ( const std::string & FileName ){
00254 }
00255
00259 void compp::File::SetGroupRD ( const std::string & FileName ){
00260 }
00261
00265 void compp::File::SetGroupWR ( const std::string & FileName ){
00266 }
00267
00271 void compp::File::SetGroupRW ( const std::string & FileName ){
00272 }
00273
00277 void compp::File::SetOthersRD ( const std::string & FileName ){
00278 }
00279
00283 void compp::File::SetOthersWR ( const std::string & FileName ){
00284 }
00285
00289 void compp::File::SetOthersRW ( const std::string & FileName ){
00290 }
00291
00292 void compp::File::Delete ( const std::string & FileName ){
00293
00294 syspp::Call::Unlink (FileName.c_str());
00295
00296 }
00297
00298
00302 void compp::File::Chmod (const std::string & FileName, mode_t mode){
00303 chmod(FileName.c_str(), mode);
00304 }