$search
00001 00009 /***************************************************************************** 00010 ** Cross platform 00011 *****************************************************************************/ 00012 00013 #include <ecl/config/ecl.hpp> 00014 #ifdef ECL_IS_POSIX 00015 00016 /***************************************************************************** 00017 ** Includes 00018 *****************************************************************************/ 00019 00020 #include <sstream> 00021 #include <errno.h> 00022 #include <ecl/exceptions/standard_exception.hpp> 00023 #include "../../../include/ecl/devices/detail/exception_handler_pos.hpp" 00024 00025 /***************************************************************************** 00026 ** Namespaces 00027 *****************************************************************************/ 00028 00029 namespace ecl { 00030 namespace devices { 00031 00032 /***************************************************************************** 00033 ** Using 00034 *****************************************************************************/ 00035 00036 using std::ostringstream; 00037 using std::string; 00038 using ecl::StandardException; 00039 00040 00041 /***************************************************************************** 00042 ** Implementation [Exception Handlers] 00043 *****************************************************************************/ 00044 00045 StandardException open_exception(const char* loc, const std::string& file_name) { 00046 int error_result = errno; 00047 switch (error_result) { 00048 case ( ENOENT ) : return StandardException(loc, ecl::NotFoundError, file_name + std::string(" could not be found.")); 00049 case ( EINVAL ) : return StandardException(loc, ecl::InvalidArgError, "File mode setting (read/write/append) was incorrectly specified."); 00050 case ( EACCES ) : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Access permission was denied.")); 00051 case ( EFBIG ) : case (EOVERFLOW) : 00052 return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". File was too large (you need to use alternative api/configuration).")); 00053 case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, string("Could not open ")+file_name+string(". Interrupted by a signal while opening.")); 00054 case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". This is a directory and not a file.")); 00055 case ( ELOOP ) : return StandardException(loc, ecl::SystemFailureError, string("Could not open ")+file_name+string(". Very nested symbolic link hell.")); 00056 case ( EMFILE ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". This process has already maxxed out its permitted number of open files.")); 00057 case ( ENFILE ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". This system has already maxxed out its permitted number of open files.")); 00058 case ( ENAMETOOLONG ) : return StandardException(loc, ecl::InvalidArgError, string("Could not open ")+file_name+string(". The file name is too long.")); 00059 case ( ENOMEM ) : return StandardException(loc, ecl::MemoryError, string("Could not open ")+file_name+string(". Insufficient memory.")); 00060 case ( ENOSPC ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". The container device (usually hard disk) has insufficient space to create the file.")); 00061 case ( ENOTDIR ): return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". Pathname invalid (a directory was not a directory).")); 00062 case ( EROFS ) : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Trying to write to a readonly file system.")); 00063 case ( ETXTBSY ): return StandardException(loc, ecl::UsageError, string("Could not open ")+file_name+string(". Trying to write to a currently executing file.")); 00064 default : 00065 { 00066 ostringstream ostream; 00067 ostream << "Unknown errno " << error_result << " [" << strerror(error_result) << "]"; 00068 return StandardException(loc, UnknownError, ostream.str()); 00069 } 00070 } 00071 } 00072 00073 00074 StandardException write_exception(const char* loc) { 00075 int error_result = errno; 00076 switch (error_result) { 00077 case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the write would block."); 00078 case ( EBADF ) : case (EINVAL) 00079 : return StandardException(loc, ecl::InvalidObjectError, "The device is not a valid device for writing."); 00080 case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's write buffer is outside your accessible address space."); 00081 case ( EFBIG ) : return StandardException(loc, ecl::MemoryError, "Tried to write beyond the device's (or process's) size limit."); 00082 case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the write."); 00083 case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control)."); 00084 case ( ENOSPC ) : return StandardException(loc, ecl::OutOfResourcesError, "The device has no room left for the data you are trying to write."); 00085 case ( EPIPE ) : return StandardException(loc, ecl::PermissionsError, "You tried to write to a pipe whose reading end is closed."); 00086 default : 00087 { 00088 ostringstream ostream; 00089 ostream << "Unknown error " << error_result << ": " << strerror(error_result) << "."; 00090 return StandardException(loc, UnknownError, ostream.str()); 00091 } 00092 } 00093 } 00094 00095 00096 StandardException read_exception(const char* loc) { 00097 int error_result = errno; 00098 switch (error_result) { 00099 case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the read would block."); 00100 case ( EBADF ) : case (EINVAL) 00101 : return StandardException(loc, ecl::PermissionsError, "The device is not a valid device for reading."); 00102 case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's read buffer is outside your accessible address space."); 00103 case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the read."); 00104 case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control)."); 00105 case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, "The file descriptor refers to a directory (not readable)."); 00106 default : 00107 { 00108 ostringstream ostream; 00109 ostream << "Unknown error " << error_result << ": " << strerror(error_result) << "."; 00110 return StandardException(loc, UnknownError, ostream.str()); 00111 } 00112 } 00113 } 00114 StandardException sync_exception(const char* loc, const std::string &file_name) { 00115 int error_result = errno; 00116 switch (error_result) { 00117 case ( EBADF ) : return StandardException(loc, ecl::InvalidArgError, string("Could not sync ") + file_name + string(", the file descriptor was not valid for writing.")); 00118 case ( EIO ) : return StandardException(loc, ecl::CloseError, string("Could not sync ") + file_name + string(", could not synchronize while closing.")); 00119 case ( EROFS ) : case ( EINVAL ) 00120 : return StandardException(loc, ecl::NotSupportedError, string("Could not sync ") + file_name + string(", file descriptor does not support synchronization.")); 00121 default : 00122 { 00123 ostringstream ostream; 00124 ostream << "Unknown error " << error_result << ": " << strerror(error_result) << "."; 00125 return StandardException(loc, UnknownError, ostream.str()); 00126 } 00127 } 00128 } 00129 StandardException close_exception(const char* loc, const std::string &file_name) { 00130 int error_result = errno; 00131 switch (error_result) { 00132 case ( EBADF ) : return StandardException(loc, ecl::InvalidArgError, string("Could not close ") + file_name + string(". The associated file descriptor was not valid.")); 00133 case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, string("Could not close ") + file_name + string(". Closing io problem.")); 00134 case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, string("Could not close ") + file_name + string(". Interrupted by a signal.")); 00135 default : 00136 { 00137 ostringstream ostream; 00138 ostream << "Unknown error " << error_result << ": " << strerror(error_result) << "."; 00139 return StandardException(loc, UnknownError, ostream.str()); 00140 } 00141 } 00142 } 00143 00144 } // namespace devices 00145 } // namespace ecl 00146 00147 #endif /* ECL_IS_POSIX */ 00148