Update of /cvsroot/boost/boost/libs/system/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14724/src

Modified Files:
      Tag: c++0x
        error_code.cpp 
Log Message:
Posix update, reflecting fact that real operating systems are never pure posix

Index: error_code.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/system/src/error_code.cpp,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -u -d -r1.8.2.1 -r1.8.2.2
--- error_code.cpp      17 Jun 2007 15:55:39 -0000      1.8.2.1
+++ error_code.cpp      18 Jun 2007 20:01:47 -0000      1.8.2.2
@@ -49,126 +49,201 @@
 namespace
 {
 
-  //  Windows native -> errno decode table  
----------------------------------//  
-
-#ifdef BOOST_WINDOWS_API
-  struct native_to_errno_t
+  struct native_to_posix_t
   { 
-    boost::int32_t native_value;
-    int posix_errno;
+    int native_value;
+    boost::system::posix_errno posix_value;
   };
 
-  const native_to_errno_t native_to_errno[] = 
+  const native_to_posix_t native_to_posix[] = 
   {
+
+#ifdef BOOST_POSIX_API
+  //  POSIX-like O/S -> posix_errno decode table  
----------------------------//
+
+    // most common errors first to speed sequential search
+    { ENOENT, no_such_file_or_directory },
+    { EACCES, permission_denied },
+    { EINVAL, invalid_argument },
+
+    // rest are alphabetical for easy maintenance
+    { 0, no_error }, 
+    { E2BIG, argument_list_too_long },
+    { EADDRINUSE, address_in_use },
+    { EADDRNOTAVAIL, address_not_available },
+    { EAFNOSUPPORT, address_family_not_supported },
+    { EAGAIN, resource_unavailable_try_again },
+    { EALREADY, connection_already_in_progress },
+    { EBADF, bad_file_descriptor },
+    { EBADMSG, bad_message },
+    { EBUSY, device_or_resource_busy },
+    { ECANCELED, operation_canceled },
+    { ECHILD, no_child_process },
+    { ECONNABORTED, connection_aborted },
+    { ECONNREFUSED, connection_refused },
+    { ECONNRESET, connection_reset },
+    { EDEADLK, resource_deadlock_would_occur },
+    { EDESTADDRREQ, destination_address_required },
+    { EDOM, argument_out_of_domain },
+    { EEXIST, file_exists },
+    { EFAULT, bad_address },
+    { EFBIG, file_too_large },
+    { EHOSTUNREACH, host_unreachable },
+    { EIDRM, identifier_removed },
+    { EILSEQ, illegal_byte_sequence },
+    { EINPROGRESS, operation_in_progress },
+    { EINTR, interrupted },
+    { EIO, io_error },
+    { EISCONN, already_connected },
+    { EISDIR, is_a_directory },
+    { ELOOP, too_many_synbolic_link_levels },
+    { EMFILE, too_many_files_open },
+    { EMLINK, too_many_links },
+    { EMSGSIZE, message_size },
+    { ENAMETOOLONG, filename_too_long },
+    { ENETDOWN, network_down },
+    { ENETRESET, network_reset },
+    { ENETUNREACH, network_unreachable },
+    { ENFILE, too_many_files_open_in_system },
+    { ENOBUFS, no_buffer_space },
+    { ENODATA, no_message_available },
+    { ENODEV, no_such_device },
+    { ENOEXEC, executable_format_error },
+    { ENOLCK, no_lock_available },
+    { ENOLINK, no_link },
+    { ENOMEM, not_enough_memory },
+    { ENOMSG, no_message },
+    { ENOPROTOOPT, no_protocol_option },
+    { ENOSPC, no_space_on_device },
+    { ENOSR, no_stream_resources },
+    { ENOSTR, not_a_stream },
+    { ENOSYS, function_not_supported },
+    { ENOTCONN, not_connected },
+    { ENOTDIR, not_a_directory },
+    { ENOTEMPTY, directory_not_empty },
+    { ENOTRECOVERABLE, state_not_recoverable },
+    { ENOTSOCK, not_a_socket },
+    { ENOTSUP, not_supported },
+    { ENOTTY, inappropriate_io_control_operation },
+    { ENXIO, no_such_device_or_address },
+    { EOPNOTSUPP, operation_not_supported },
+    { EOVERFLOW, value_too_large },
+    { EOWNERDEAD, owner_dead },
+    { EPERM, operation_not_permitted },
+    { EPIPE, broken_pipe },
+    { EPROTO, protocol_error },
+    { EPROTONOSUPPORT, protocol_not_supported },
+    { EPROTOTYPE, wrong_protocol_type },
+    { ERANGE, result_out_of_range },
+    { EROFS, read_only_file_system },
+    { ESPIPE, invalid_seek },
+    { ESRCH, no_such_process },
+    { ETIME, stream_timeout },
+    { ETIMEDOUT, timed_out },
+    { ETXTBSY, text_file_busy },
+    { EWOULDBLOCK, operation_would_block },
+    { EXDEV, cross_device_link }
+
+#else
+
+  //  Windows native -> posix_errno decode table  
----------------------------//  
+
     // see WinError.h comments for descriptions of errors
     
     // most common errors first to speed sequential search
-    { ERROR_FILE_NOT_FOUND, ENOENT },
-    { ERROR_PATH_NOT_FOUND, ENOENT },
+    { ERROR_FILE_NOT_FOUND, no_such_file_or_directory },
+    { ERROR_PATH_NOT_FOUND, no_such_file_or_directory },
 
     // rest are alphabetical for easy maintenance
-    { 0, 0 }, // no error 
-    { ERROR_ACCESS_DENIED, EACCES },
-    { ERROR_ALREADY_EXISTS, EEXIST },
-    { ERROR_BAD_UNIT, ENODEV },
-    { ERROR_BUFFER_OVERFLOW, ENAMETOOLONG },
-    { ERROR_BUSY, EBUSY },
-    { ERROR_BUSY_DRIVE, EBUSY },
-    { ERROR_CANNOT_MAKE, EACCES },
-    { ERROR_CANTOPEN, EIO },
-    { ERROR_CANTREAD, EIO },
-    { ERROR_CANTWRITE, EIO },
-    { ERROR_CURRENT_DIRECTORY, EACCES },
-    { ERROR_DEV_NOT_EXIST, ENODEV },
-    { ERROR_DEVICE_IN_USE, EBUSY },
-    { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
-    { ERROR_DIRECTORY, EINVAL }, // WinError.h: "The directory name is invalid"
-    { ERROR_DISK_FULL, ENOSPC },
-    { ERROR_FILE_EXISTS, EEXIST },
-    { ERROR_HANDLE_DISK_FULL, ENOSPC },
-    { ERROR_INVALID_ACCESS, EACCES },
-    { ERROR_INVALID_DRIVE, ENODEV },
-    { ERROR_INVALID_FUNCTION, ENOSYS },
-    { ERROR_INVALID_HANDLE, EBADHANDLE },
-    { ERROR_INVALID_NAME, EINVAL },
-    { ERROR_LOCK_VIOLATION, EACCES },
-    { ERROR_LOCKED, EACCES },
-    { ERROR_NEGATIVE_SEEK, EINVAL },
-    { ERROR_NOACCESS, EACCES },
-    { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
-    { ERROR_NOT_READY, EAGAIN },
-    { ERROR_NOT_SAME_DEVICE, EXDEV },
-    { ERROR_OPEN_FAILED, EIO },
-    { ERROR_OPEN_FILES, EBUSY },
-    { ERROR_OUTOFMEMORY, ENOMEM },
-    { ERROR_READ_FAULT, EIO },
-    { ERROR_SEEK, EIO },
-    { ERROR_SHARING_VIOLATION, EACCES },
-    { ERROR_TOO_MANY_OPEN_FILES, ENFILE },
-    { ERROR_WRITE_FAULT, EIO },
-    { ERROR_WRITE_PROTECT, EROFS }
-  };
+    { 0, no_error }, 
+    { ERROR_ACCESS_DENIED, permission_denied },
+    { ERROR_ALREADY_EXISTS, file_exists },
+    { ERROR_BAD_UNIT, no_such_device },
+    { ERROR_BUFFER_OVERFLOW, filename_too_long },
+    { ERROR_BUSY, device_or_resource_busy },
+    { ERROR_BUSY_DRIVE, device_or_resource_busy },
+    { ERROR_CANNOT_MAKE, permission_denied },
+    { ERROR_CANTOPEN, io_error },
+    { ERROR_CANTREAD, io_error },
+    { ERROR_CANTWRITE, io_error },
+    { ERROR_CURRENT_DIRECTORY, permission_denied },
+    { ERROR_DEV_NOT_EXIST, no_such_device },
+    { ERROR_DEVICE_IN_USE, device_or_resource_busy },
+    { ERROR_DIR_NOT_EMPTY, directory_not_empty },
+    { ERROR_DIRECTORY, invalid_argument }, // WinError.h: "The directory name 
is invalid"
+    { ERROR_DISK_FULL, no_space_on_device },
+    { ERROR_FILE_EXISTS, file_exists },
+    { ERROR_HANDLE_DISK_FULL, no_space_on_device },
+    { ERROR_INVALID_ACCESS, permission_denied },
+    { ERROR_INVALID_DRIVE, no_such_device },
+    { ERROR_INVALID_FUNCTION, function_not_supported },
+    { ERROR_INVALID_HANDLE, invalid_argument },
+    { ERROR_INVALID_NAME, invalid_argument },
+    { ERROR_LOCK_VIOLATION, no_lock_available },
+    { ERROR_LOCKED, no_lock_available },
+    { ERROR_NEGATIVE_SEEK, invalid_argument },
+    { ERROR_NOACCESS, permission_denied },
+    { ERROR_NOT_ENOUGH_MEMORY, not_enough_memory },
+    { ERROR_NOT_READY, resource_unavailable_try_again },
+    { ERROR_NOT_SAME_DEVICE, cross_device_link },
+    { ERROR_OPEN_FAILED, io_error },
+    { ERROR_OPEN_FILES, device_or_resource_busy },
+    { ERROR_OUTOFMEMORY, not_enough_memory },
+    { ERROR_READ_FAULT, io_error },
+    { ERROR_SEEK, io_error },
+    { ERROR_SHARING_VIOLATION, permission_denied },
+    { ERROR_TOO_MANY_OPEN_FILES, too_many_files_open },
+    { ERROR_WRITE_FAULT, io_error },
+    { ERROR_WRITE_PROTECT, permission_denied }
 
 #endif
+  };
 
-} // unnamed namespace
+  //  standard error categories  -------------------------------------------//
 
-namespace boost
-{
-  namespace system
+  class posix_error_category : public error_category
   {
-    //  standard error categories  
-------------------------------------------//
-
-    class BOOST_SYSTEM_DECL posix_error_category : public error_category
-    {
-    public:
-      const std::string &   name() const;
-      posix_errno           posix( int ev ) const;
-      std::string           message( int ev ) const;
-      wstring_t_workaround  wmessage( int ev ) const;
-    };
-  
-# ifdef BOOST_POSIX_API
-    typedef posix_error_category native_error_category;
-# else
-    class BOOST_SYSTEM_DECL native_error_category  : public error_category
-    {
-    public:
-      const std::string &   name() const;
-      posix_errno           posix( int ev ) const;
-      std::string           message( int ev ) const;
-      wstring_t_workaround  wmessage( int ev ) const;
-    };
-# endif
+  public:
+    const std::string &   name() const;
+    posix_errno           posix( int ev ) const;
+    std::string           message( int ev ) const;
+    wstring_t_workaround  wmessage( int ev ) const;
+  };
 
-    const posix_error_category posix_category_const;
-    BOOST_SYSTEM_DECL const error_category & posix_category = 
posix_category_const;
+  class native_error_category : public error_category
+  {
+  public:
+    const std::string &   name() const;
+    posix_errno           posix( int ev ) const;
+    std::string           message( int ev ) const;
+    wstring_t_workaround  wmessage( int ev ) const;
+  };
 
-    const native_error_category native_category_const;
-    BOOST_SYSTEM_DECL const error_category & native_category = 
native_category_const;
+  const posix_error_category posix_category_const;
+  const native_error_category native_category_const;
 
-    //  errno_error_category implementation  
---------------------------------//
+  //  posix_error_category implementation  ---------------------------------//
 
-    const std::string & posix_error_category::name() const
-    {
-      static std::string s( "POSIX" );
-      return s;
-    }
+  const std::string & posix_error_category::name() const
+  {
+    static const std::string s( "POSIX" );
+    return s;
+  }
 
-    posix_errno posix_error_category::posix( int ev ) const
-    {
-      return static_cast<posix_errno>(ev);
-    }
+  posix_errno posix_error_category::posix( int ev ) const
+  {
+    return static_cast<posix_errno>(ev);
+  }
 
-    std::string posix_error_category::message( int ev ) const
-    {
-    // strerror_r is preferred because it is always thread safe,
-    // however, we fallback to strerror in certain cases because:
-    //   -- Windows doesn't provide strerror_r.
-    //   -- HP and Sundo provide strerror_r on newer systems, but there is
-    //      no way to tell if is available at runtime and in any case their
-    //      versions of strerror are thread safe anyhow.
-    //   -- Linux only sometimes provides strerror_r.
+  std::string posix_error_category::message( int ev ) const
+  {
+  // strerror_r is preferred because it is always thread safe,
+  // however, we fallback to strerror in certain cases because:
+  //   -- Windows doesn't provide strerror_r.
+  //   -- HP and Sundo provide strerror_r on newer systems, but there is
+  //      no way to tell if is available at runtime and in any case their
+  //      versions of strerror are thread safe anyhow.
+  //   -- Linux only sometimes provides strerror_r.
   //   -- Tru64 provides strerror_r only when compiled -pthread.
   //   -- VMS doesn't provide strerror_r, but on this platform, strerror is
   //      thread safe.
@@ -177,7 +252,7 @@
      || (defined(__osf__) && !defined(_REENTRANT))\
      || (defined(__vms))
       const char * c_str = std::strerror( ev );
-      return std::string( c_str ? c_str : "EINVAL" );
+      return std::string( c_str ? c_str : "invalid_argument" );
   # else
       char buf[64];
       char * bp = buf;
@@ -185,14 +260,14 @@
   #  if defined(__CYGWIN__) || defined(__USE_GNU)
       // Oddball version of strerror_r
       const char * c_str = strerror_r( ev, bp, sz );
-      return std::string( c_str ? c_str : "EINVAL" );
+      return std::string( c_str ? c_str : "invalid_argument" );
   #  else
       // POSIX version of strerror_r
       int result;
       for (;;)
       {
         // strerror_r returns 0 on success, otherwise ERANGE if buffer too 
small,
-        // EINVAL if ev not a valid error number
+        // invalid_argument if ev not a valid error number
         if ( (result = strerror_r( ev, bp, sz )) == 0 )
           break;
         else
@@ -210,7 +285,7 @@
       }
       try
       {
-      std::string msg( ( result == EINVAL ) ? "EINVAL" : bp );
+      std::string msg( ( result == invalid_argument ) ? "invalid_argument" : 
bp );
       if ( sz > sizeof(buf) ) std::free( bp );
         sz = 0;
       return msg;
@@ -222,55 +297,51 @@
       }
   #  endif
   # endif
-    }
+  }
 
-    wstring_t_workaround posix_error_category::wmessage( int ev ) const
-    {
-      std::string str = message( ev );
-      wstring_t_workaround wstr;
+  wstring_t_workaround posix_error_category::wmessage( int ev ) const
+  {
+    std::string str = message( ev );
+    wstring_t_workaround wstr;
 
-      for (std::size_t i = 0; i < str.size(); ++i )
-        { wstr += static_cast<wchar_t>(str[i]); }
-      return wstr;
-    }
+    for (std::size_t i = 0; i < str.size(); ++i )
+      { wstr += static_cast<wchar_t>(str[i]); }
+    return wstr;
+  }
 
-    //  native_error_category implementation  
--------------------------------// 
+  //  native_error_category implementation  --------------------------------// 
 
-    const std::string & native_error_category::name() const
+  const std::string & native_error_category::name() const
+  {
+    static const std::string s( "native" );
+    return s;
+  }
+
+  posix_errno native_error_category::posix( int ev ) const
+  {
+    const native_to_posix_t * cur = native_to_posix;
+    do
     {
-      static std::string s( "native" );
-      return s;
-    }
+      if ( ev == cur->native_value )
+        return cur->posix_value;
+      ++cur;
+    } while ( cur != native_to_posix
+      + sizeof(native_to_posix)/sizeof(native_to_posix_t) );
+    return boost::system::other;
+  }
 
 # if !defined( BOOST_WINDOWS_API )
-    int native_error_category::posix( boost::int_least32_t ev ) const
-    {
-      return ev;
-    }
 
-    std::string native_error_category::message( boost::int_least32_t ev ) const
-    {
-      return posix_category.message( ev );
-    }
+  std::string native_error_category::message( boost::int_least32_t ev ) const
+  {
+    return posix_category.message( ev );
+  }
 
-    wstring_t native_error_category::wmessage( boost::int_least32_t ev ) const
-    {
-      return posix_category.wmessage( ev );
-    }
+  wstring_t native_error_category::wmessage( boost::int_least32_t ev ) const
+  {
+    return posix_category.wmessage( ev );
+  }
 # else
-    posix_errno native_error_category::posix( int ev ) const
-    {
-      const native_to_errno_t * cur = native_to_errno;
-      do
-      {
-        if ( ev == cur->native_value )
-          return static_cast<posix_errno>(cur->posix_errno);
-        ++cur;
-      } while ( cur != native_to_errno
-        + sizeof(native_to_errno)/sizeof(native_to_errno_t) );
-      return static_cast<posix_errno>(EOTHER);
-    }
-
 // TODO:
   
 //Some quick notes on the implementation (sorry for the noise if
@@ -286,49 +357,58 @@
 //
 //Cheers,
 //Chris
-    std::string native_error_category::message( int ev ) const
-    {
-      LPVOID lpMsgBuf;
-      ::FormatMessageA( 
-          FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-          FORMAT_MESSAGE_FROM_SYSTEM | 
-          FORMAT_MESSAGE_IGNORE_INSERTS,
-          NULL,
-          ev,
-          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-          (LPSTR) &lpMsgBuf,
-          0,
-          NULL 
-      );
-      std::string str( static_cast<LPCSTR>(lpMsgBuf) );
-      ::LocalFree( lpMsgBuf ); // free the buffer
-      while ( str.size()
-        && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
-          str.erase( str.size()-1 );
-      return str;
-    }
+  std::string native_error_category::message( int ev ) const
+  {
+    LPVOID lpMsgBuf;
+    ::FormatMessageA( 
+        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+        FORMAT_MESSAGE_FROM_SYSTEM | 
+        FORMAT_MESSAGE_IGNORE_INSERTS,
+        NULL,
+        ev,
+        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+        (LPSTR) &lpMsgBuf,
+        0,
+        NULL 
+    );
+    std::string str( static_cast<LPCSTR>(lpMsgBuf) );
+    ::LocalFree( lpMsgBuf ); // free the buffer
+    while ( str.size()
+      && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
+        str.erase( str.size()-1 );
+    return str;
+  }
 
-    wstring_t_workaround native_error_category::wmessage( int ev ) const
-    {
-      LPVOID lpMsgBuf;
-      ::FormatMessageW( 
-          FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-          FORMAT_MESSAGE_FROM_SYSTEM | 
-          FORMAT_MESSAGE_IGNORE_INSERTS,
-          NULL,
-          ev,
-          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-          (LPWSTR) &lpMsgBuf,
-          0,
-          NULL 
-      );
-      wstring_t_workaround str( static_cast<LPCWSTR>(lpMsgBuf) );
-      ::LocalFree( lpMsgBuf ); // free the buffer
-      while ( str.size()
-        && (str[str.size()-1] == L'\n' || str[str.size()-1] == L'\r') )
-          str.erase( str.size()-1 );
-      return str;
-    }
+  wstring_t_workaround native_error_category::wmessage( int ev ) const
+  {
+    LPVOID lpMsgBuf;
+    ::FormatMessageW( 
+        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+        FORMAT_MESSAGE_FROM_SYSTEM | 
+        FORMAT_MESSAGE_IGNORE_INSERTS,
+        NULL,
+        ev,
+        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+        (LPWSTR) &lpMsgBuf,
+        0,
+        NULL 
+    );
+    wstring_t_workaround str( static_cast<LPCWSTR>(lpMsgBuf) );
+    ::LocalFree( lpMsgBuf ); // free the buffer
+    while ( str.size()
+      && (str[str.size()-1] == L'\n' || str[str.size()-1] == L'\r') )
+        str.erase( str.size()-1 );
+    return str;
+  }
 # endif
+
+} // unnamed namespace
+
+namespace boost
+{
+  namespace system
+  {
+    BOOST_SYSTEM_DECL const error_category & posix_category = 
posix_category_const;
+    BOOST_SYSTEM_DECL const error_category & native_category = 
native_category_const;
   } // namespace system
 } // namespace boost


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to