Changeset 709 for trunk/yat/utility/FileIO.cc
- Timestamp:
- Dec 20, 2006, 10:49:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/FileIO.cc
r687 r709 26 26 #include "FileIO.h" 27 27 28 #include <cerrno> 28 29 #include <iostream> 30 #include <string> 31 32 #include <sys/stat.h> 29 33 #include <unistd.h> 30 34 … … 34 38 namespace utility { 35 39 40 41 FileIO::FileIO(const std::string& path) 42 : no_file_(false), path_(path) 43 { 44 if ( stat(path_.c_str(),&stat_) && !(no_file_=(errno==ENOENT)) ) 45 throw IO_error(std::string("stat(2) call failed with errno: "+errno)); 46 } 47 48 36 49 int FileIO::access_rights(const std::string& path, 37 const std::string& bits) const { 38 if (int value=access(path.c_str(),F_OK)) { 39 std::cerr << "access_rights: File '" << path << "' does not exist." 40 << std::endl; 41 return value; 50 const std::string& bits) const 51 { 52 std::string tryme=path_; 53 if (no_file_) { 54 std::string::size_type pos=path_.find_last_of('/'); 55 tryme = ( (pos!=std::string::npos) ? path_.substr(0,pos) : "." ); 42 56 } 57 43 58 int mode=0; 44 59 for (u_int i=0; i<bits.length(); i++) … … 54 69 break; 55 70 } 56 return access(path.c_str(),mode); 71 72 return access(tryme.c_str(),mode); 73 } 74 75 76 bool FileIO::file_exists(const std::string& file) const 77 { 78 return !no_file_; 79 } 80 81 82 const std::string& FileIO::path(void) const 83 { 84 return path_; 57 85 } 58 86
Note: See TracChangeset
for help on using the changeset viewer.