13 #include <ecl/config/ecl.hpp> 
   22 #include "../../../include/ecl/devices/detail/exception_handler_pos.hpp" 
   35 using std::ostringstream;
 
   44 StandardException 
open_exception(
const char* loc, 
const std::string& file_name) {
 
   45         int error_result = errno;
 
   46         switch (error_result) {
 
   47                 case ( ENOENT ) : 
return StandardException(loc, 
ecl::NotFoundError, file_name + std::string(
" could not be found."));
 
   48                 case ( EINVAL ) : 
return StandardException(loc, 
ecl::InvalidArgError, 
"File mode setting (read/write/append) was incorrectly specified.");
 
   49                 case ( EACCES ) : 
return StandardException(loc, 
ecl::PermissionsError, 
string(
"Could not open ")+file_name+
string(
". Access permission was denied."));
 
   50                 case ( EFBIG )  : 
case (EOVERFLOW)  :
 
   51                                                   return StandardException(loc, 
ecl::OutOfResourcesError, 
string(
"Could not open ")+file_name+
string(
". File was too large (you need to use alternative api/configuration)."));
 
   52                 case ( EINTR )  : 
return StandardException(loc, 
ecl::InterruptedError, 
string(
"Could not open ")+file_name+
string(
". Interrupted by a signal while opening."));
 
   53                 case ( EISDIR ) : 
return StandardException(loc, 
ecl::InvalidObjectError, 
string(
"Could not open ")+file_name+
string(
". This is a directory and not a file."));
 
   54                 case ( ELOOP )  : 
return StandardException(loc, 
ecl::SystemFailureError, 
string(
"Could not open ")+file_name+
string(
". Very nested symbolic link hell."));
 
   55                 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."));
 
   59                 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."));
 
   62                 case ( ETXTBSY ): 
return StandardException(loc, 
ecl::UsageError, 
string(
"Could not open ")+file_name+
string(
". Trying to write to a currently executing file."));
 
   65                         ostringstream ostream;
 
   66                         ostream << 
"Unknown errno " << error_result << 
" [" << strerror(error_result) << 
"]";
 
   74         int error_result = errno;
 
   75         switch (error_result) {
 
   76                 case ( EAGAIN ) : 
return StandardException(loc, 
ecl::BlockingError, 
"The device has been marked non blocking and the write would block.");
 
   77                 case ( EBADF  ) : 
case (EINVAL)
 
   79                 case ( EFAULT ) : 
return StandardException(loc, 
ecl::OutOfRangeError, 
"The device's write buffer is outside your accessible address space.");
 
   80                 case ( EFBIG  ) : 
return StandardException(loc, 
ecl::MemoryError, 
"Tried to write beyond the device's (or process's) size limit.");
 
   81                 case ( EINTR )  : 
return StandardException(loc, 
ecl::InterruptedError, 
"A signal interrupted the write.");
 
   82                 case ( EIO    ) : 
return StandardException(loc, 
ecl::SystemFailureError, 
"A low level input-output error occured (possibly beyond your control).");
 
   83                 case ( ENOSPC ) : 
return StandardException(loc, 
ecl::OutOfResourcesError, 
"The device has no room left for the data you are trying to write.");
 
   84                 case ( EPIPE  ) : 
return StandardException(loc, 
ecl::PermissionsError, 
"You tried to write to a pipe whose reading end is closed.");
 
   87                         ostringstream ostream;
 
   88                         ostream << 
"Unknown error " << error_result << 
": " << strerror(error_result) << 
".";
 
   96         int error_result = errno;
 
   97         switch (error_result) {
 
   98                 case ( EAGAIN ) : 
return StandardException(loc, 
ecl::BlockingError, 
"The device has been marked non blocking and the read would block.");
 
   99                 case ( EBADF  ) : 
case (EINVAL)
 
  100                                                 : 
return StandardException(loc, 
ecl::PermissionsError, 
"The device is not a valid device for reading.");
 
  101                 case ( EFAULT ) : 
return StandardException(loc, 
ecl::OutOfRangeError, 
"The device's read buffer is outside your accessible address space.");
 
  102                 case ( EINTR )  : 
return StandardException(loc, 
ecl::InterruptedError, 
"A signal interrupted the read.");
 
  103                 case ( EIO    ) : 
return StandardException(loc, 
ecl::SystemFailureError, 
"A low level input-output error occured (possibly beyond your control).");
 
  104                 case ( EISDIR ) : 
return StandardException(loc, 
ecl::InvalidObjectError, 
"The file descriptor refers to a directory (not readable).");
 
  107                         ostringstream ostream;
 
  108                         ostream << 
"Unknown error " << error_result << 
": " << strerror(error_result) << 
".";
 
  113 StandardException 
sync_exception(
const char* loc, 
const std::string &file_name) {
 
  114         int error_result = errno;
 
  115         switch (error_result) {
 
  116                 case ( EBADF  ) : 
return StandardException(loc, 
ecl::InvalidArgError, 
string(
"Could not sync ") + file_name + 
string(
", the file descriptor was not valid for writing."));
 
  117                 case ( EIO  )   : 
return StandardException(loc, 
ecl::CloseError, 
string(
"Could not sync ") + file_name + 
string(
", could not synchronize while closing."));
 
  118                 case ( EROFS )  : 
case ( EINVAL )
 
  119                                                 : 
return StandardException(loc, 
ecl::NotSupportedError, 
string(
"Could not sync ") + file_name + 
string(
", file descriptor does not support synchronization."));
 
  122                         ostringstream ostream;
 
  123                         ostream << 
"Unknown error " << error_result << 
": " << strerror(error_result) << 
".";
 
  124                         return StandardException(loc, 
UnknownError, ostream.str());
 
  128 StandardException 
close_exception(
const char* loc, 
const std::string &file_name) {
 
  129         int error_result = errno;
 
  130         switch (error_result) {
 
  131                 case ( EBADF  ) : 
return StandardException(loc, 
ecl::InvalidArgError, 
string(
"Could not close ") + file_name + 
string(
". The associated file descriptor was not valid."));
 
  132                 case ( EIO  )   : 
return StandardException(loc, 
ecl::SystemFailureError, 
string(
"Could not close ") + file_name + 
string(
". Closing io problem."));
 
  133                 case ( EINTR )  : 
return StandardException(loc, 
ecl::InterruptedError, 
string(
"Could not close ") + file_name + 
string(
". Interrupted by a signal."));
 
  136                         ostringstream ostream;
 
  137                         ostream << 
"Unknown error " << error_result << 
": " << strerror(error_result) << 
".";
 
  138                         return StandardException(loc, 
UnknownError, ostream.str());