Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/interprocess for documentation. Chris@16: // Chris@16: // Parts of this code are taken from boost::filesystem library Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // Copyright (C) 2002 Beman Dawes Chris@16: // Copyright (C) 2001 Dietmar Kuehl Chris@16: // Use, modification, and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy Chris@16: // at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See library home page at http://www.boost.org/libs/filesystem Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: Chris@16: #ifndef BOOST_INTERPROCESS_ERRORS_HPP Chris@16: #define BOOST_INTERPROCESS_ERRORS_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: # Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: # include Chris@16: #else Chris@16: # ifdef BOOST_HAS_UNISTD_H Chris@16: # include //Errors Chris@16: # include //strerror Chris@16: # else //ifdef BOOST_HAS_UNISTD_H Chris@16: # error Unknown platform Chris@16: # endif //ifdef BOOST_HAS_UNISTD_H Chris@101: #endif //#if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: Chris@16: //!\file Chris@16: //!Describes the error numbering of interprocess classes Chris@16: Chris@16: namespace boost { Chris@16: namespace interprocess { Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: inline int system_error_code() // artifact of POSIX and WINDOWS error reporting Chris@16: { Chris@101: #if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: return winapi::get_last_error(); Chris@16: #else Chris@16: return errno; // GCC 3.1 won't accept ::errno Chris@16: #endif Chris@16: } Chris@16: Chris@16: Chris@101: #if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: inline void fill_system_message(int sys_err_code, std::string &str) Chris@16: { Chris@16: void *lpMsgBuf; Chris@16: winapi::format_message( Chris@16: winapi::format_message_allocate_buffer | Chris@16: winapi::format_message_from_system | Chris@16: winapi::format_message_ignore_inserts, Chris@16: 0, Chris@16: sys_err_code, Chris@16: winapi::make_lang_id(winapi::lang_neutral, winapi::sublang_default), // Default language Chris@16: reinterpret_cast(&lpMsgBuf), Chris@16: 0, Chris@16: 0 Chris@16: ); Chris@16: str += static_cast(lpMsgBuf); Chris@16: winapi::local_free( lpMsgBuf ); // free the buffer Chris@16: while ( str.size() Chris@16: && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') ) Chris@16: str.erase( str.size()-1 ); Chris@16: } Chris@16: # else Chris@16: inline void fill_system_message( int system_error, std::string &str) Chris@16: { str = std::strerror(system_error); } Chris@16: # endif Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: enum error_code_t Chris@16: { Chris@16: no_error = 0, Chris@16: system_error, // system generated error; if possible, is translated Chris@16: // to one of the more specific errors below. Chris@16: other_error, // library generated error Chris@16: security_error, // includes access rights, permissions failures Chris@16: read_only_error, Chris@16: io_error, Chris@16: path_error, Chris@16: not_found_error, Chris@16: // not_directory_error, Chris@16: busy_error, // implies trying again might succeed Chris@16: already_exists_error, Chris@16: not_empty_error, Chris@16: is_directory_error, Chris@16: out_of_space_error, Chris@16: out_of_memory_error, Chris@16: out_of_resource_error, Chris@16: lock_error, Chris@16: sem_error, Chris@16: mode_error, Chris@16: size_error, Chris@16: corrupted_error, Chris@16: not_such_file_or_directory, Chris@16: invalid_argument, Chris@16: timeout_when_locking_error, Chris@101: timeout_when_waiting_error, Chris@101: owner_dead_error Chris@16: }; Chris@16: Chris@16: typedef int native_error_t; Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: struct ec_xlate Chris@16: { Chris@16: native_error_t sys_ec; Chris@16: error_code_t ec; Chris@16: }; Chris@16: Chris@16: static const ec_xlate ec_table[] = Chris@16: { Chris@101: #if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: { /*ERROR_ACCESS_DENIED*/5L, security_error }, Chris@16: { /*ERROR_INVALID_ACCESS*/12L, security_error }, Chris@16: { /*ERROR_SHARING_VIOLATION*/32L, security_error }, Chris@16: { /*ERROR_LOCK_VIOLATION*/33L, security_error }, Chris@16: { /*ERROR_LOCKED*/212L, security_error }, Chris@16: { /*ERROR_NOACCESS*/998L, security_error }, Chris@16: { /*ERROR_WRITE_PROTECT*/19L, read_only_error }, Chris@16: { /*ERROR_NOT_READY*/21L, io_error }, Chris@16: { /*ERROR_SEEK*/25L, io_error }, Chris@16: { /*ERROR_READ_FAULT*/30L, io_error }, Chris@16: { /*ERROR_WRITE_FAULT*/29L, io_error }, Chris@16: { /*ERROR_CANTOPEN*/1011L, io_error }, Chris@16: { /*ERROR_CANTREAD*/1012L, io_error }, Chris@16: { /*ERROR_CANTWRITE*/1013L, io_error }, Chris@16: { /*ERROR_DIRECTORY*/267L, path_error }, Chris@16: { /*ERROR_INVALID_NAME*/123L, path_error }, Chris@16: { /*ERROR_FILE_NOT_FOUND*/2L, not_found_error }, Chris@16: { /*ERROR_PATH_NOT_FOUND*/3L, not_found_error }, Chris@16: { /*ERROR_DEV_NOT_EXIST*/55L, not_found_error }, Chris@16: { /*ERROR_DEVICE_IN_USE*/2404L, busy_error }, Chris@16: { /*ERROR_OPEN_FILES*/2401L, busy_error }, Chris@16: { /*ERROR_BUSY_DRIVE*/142L, busy_error }, Chris@16: { /*ERROR_BUSY*/170L, busy_error }, Chris@16: { /*ERROR_FILE_EXISTS*/80L, already_exists_error }, Chris@16: { /*ERROR_ALREADY_EXISTS*/183L, already_exists_error }, Chris@16: { /*ERROR_DIR_NOT_EMPTY*/145L, not_empty_error }, Chris@16: { /*ERROR_HANDLE_DISK_FULL*/39L, out_of_space_error }, Chris@16: { /*ERROR_DISK_FULL*/112L, out_of_space_error }, Chris@16: { /*ERROR_OUTOFMEMORY*/14L, out_of_memory_error }, Chris@16: { /*ERROR_NOT_ENOUGH_MEMORY*/8L, out_of_memory_error }, Chris@16: { /*ERROR_TOO_MANY_OPEN_FILES*/4L, out_of_resource_error }, Chris@16: { /*ERROR_INVALID_ADDRESS*/487L, busy_error } Chris@101: #else //#if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: { EACCES, security_error }, Chris@16: { EROFS, read_only_error }, Chris@16: { EIO, io_error }, Chris@16: { ENAMETOOLONG, path_error }, Chris@16: { ENOENT, not_found_error }, Chris@16: // { ENOTDIR, not_directory_error }, Chris@16: { EAGAIN, busy_error }, Chris@16: { EBUSY, busy_error }, Chris@16: { ETXTBSY, busy_error }, Chris@16: { EEXIST, already_exists_error }, Chris@16: { ENOTEMPTY, not_empty_error }, Chris@16: { EISDIR, is_directory_error }, Chris@16: { ENOSPC, out_of_space_error }, Chris@16: { ENOMEM, out_of_memory_error }, Chris@16: { EMFILE, out_of_resource_error }, Chris@16: { ENOENT, not_such_file_or_directory }, Chris@16: { EINVAL, invalid_argument } Chris@101: #endif //#if defined (BOOST_INTERPROCESS_WINDOWS) Chris@16: }; Chris@16: Chris@16: inline error_code_t lookup_error(native_error_t err) Chris@16: { Chris@16: const ec_xlate *cur = &ec_table[0], Chris@16: *end = cur + sizeof(ec_table)/sizeof(ec_xlate); Chris@16: for (;cur != end; ++cur ){ Chris@16: if ( err == cur->sys_ec ) return cur->ec; Chris@16: } Chris@16: return system_error; // general system error code Chris@16: } Chris@16: Chris@16: struct error_info Chris@16: { Chris@16: error_info(error_code_t ec = other_error ) Chris@16: : m_nat(0), m_ec(ec) Chris@16: {} Chris@16: Chris@16: error_info(native_error_t sys_err_code) Chris@16: : m_nat(sys_err_code), m_ec(lookup_error(sys_err_code)) Chris@16: {} Chris@16: Chris@16: error_info & operator =(error_code_t ec) Chris@16: { Chris@16: m_nat = 0; Chris@16: m_ec = ec; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: error_info & operator =(native_error_t sys_err_code) Chris@16: { Chris@16: m_nat = sys_err_code; Chris@16: m_ec = lookup_error(sys_err_code); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: native_error_t get_native_error()const Chris@16: { return m_nat; } Chris@16: Chris@16: error_code_t get_error_code()const Chris@16: { return m_ec; } Chris@16: Chris@16: private: Chris@16: native_error_t m_nat; Chris@16: error_code_t m_ec; Chris@16: }; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: } // namespace interprocess { Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_INTERPROCESS_ERRORS_HPP