File indexing completed on 2025-01-18 09:38:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef BOOST_INTERPROCESS_ERRORS_HPP
0025 #define BOOST_INTERPROCESS_ERRORS_HPP
0026
0027 #ifndef BOOST_CONFIG_HPP
0028 # include <boost/config.hpp>
0029 #endif
0030 #
0031 #if defined(BOOST_HAS_PRAGMA_ONCE)
0032 # pragma once
0033 #endif
0034
0035 #include <boost/interprocess/detail/config_begin.hpp>
0036 #include <boost/interprocess/detail/workaround.hpp>
0037 #include <string>
0038
0039 #if defined (BOOST_INTERPROCESS_WINDOWS)
0040 # include <boost/interprocess/detail/win32_api.hpp>
0041 #else
0042 # ifdef BOOST_HAS_UNISTD_H
0043 # include <cerrno> //Errors
0044 # include <cstring> //strerror
0045 # else
0046 # error Unknown platform
0047 # endif
0048 #endif
0049
0050
0051
0052
0053 namespace boost {
0054 namespace interprocess {
0055 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0056 inline int system_error_code()
0057 {
0058 #if defined (BOOST_INTERPROCESS_WINDOWS)
0059 return (int)winapi::get_last_error();
0060 #else
0061 return errno;
0062 #endif
0063 }
0064
0065
0066 #if defined (BOOST_INTERPROCESS_WINDOWS)
0067 inline void fill_system_message(int sys_err_code, std::string &str)
0068 {
0069 void *lpMsgBuf;
0070 unsigned long ret = winapi::format_message(
0071 winapi::format_message_allocate_buffer |
0072 winapi::format_message_from_system |
0073 winapi::format_message_ignore_inserts,
0074 0,
0075 (unsigned long)sys_err_code,
0076 winapi::make_lang_id(winapi::lang_neutral, winapi::sublang_default),
0077 reinterpret_cast<char *>(&lpMsgBuf),
0078 0,
0079 0
0080 );
0081 if (ret != 0){
0082 str += static_cast<const char*>(lpMsgBuf);
0083 winapi::local_free( lpMsgBuf );
0084 while ( str.size()
0085 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
0086 str.erase( str.size()-1 );
0087 }
0088 else{
0089 str += "WinApi FormatMessage returned error";
0090 }
0091 }
0092 # else
0093 inline void fill_system_message( int system_error, std::string &str)
0094 { str = std::strerror(system_error); }
0095 # endif
0096 #endif
0097
0098 enum error_code_t
0099 {
0100 no_error = 0,
0101 system_error,
0102
0103 other_error,
0104 security_error,
0105 read_only_error,
0106 io_error,
0107 path_error,
0108 not_found_error,
0109
0110 busy_error,
0111 already_exists_error,
0112 not_empty_error,
0113 is_directory_error,
0114 out_of_space_error,
0115 out_of_memory_error,
0116 out_of_resource_error,
0117 lock_error,
0118 sem_error,
0119 mode_error,
0120 size_error,
0121 corrupted_error,
0122 not_such_file_or_directory,
0123 invalid_argument,
0124 timeout_when_locking_error,
0125 timeout_when_waiting_error,
0126 owner_dead_error,
0127 not_recoverable
0128 };
0129
0130 typedef int native_error_t;
0131
0132 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0133 struct ec_xlate
0134 {
0135 native_error_t sys_ec;
0136 error_code_t ec;
0137 };
0138
0139 static const ec_xlate ec_table[] =
0140 {
0141 #if defined (BOOST_INTERPROCESS_WINDOWS)
0142 { 5L, security_error },
0143 { 12L, security_error },
0144 { 32L, security_error },
0145 { 33L, security_error },
0146 { 212L, security_error },
0147 { 998L, security_error },
0148 { 19L, read_only_error },
0149 { 21L, io_error },
0150 { 25L, io_error },
0151 { 30L, io_error },
0152 { 29L, io_error },
0153 { 1011L, io_error },
0154 { 1012L, io_error },
0155 { 1013L, io_error },
0156 { 267L, path_error },
0157 { 123L, path_error },
0158 { 2L, not_found_error },
0159 { 3L, not_found_error },
0160 { 55L, not_found_error },
0161 { 2404L, busy_error },
0162 { 2401L, busy_error },
0163 { 142L, busy_error },
0164 { 170L, busy_error },
0165 { 80L, already_exists_error },
0166 { 183L, already_exists_error },
0167 { 145L, not_empty_error },
0168 { 39L, out_of_space_error },
0169 { 112L, out_of_space_error },
0170 { 14L, out_of_memory_error },
0171 { 8L, out_of_memory_error },
0172 { 4L, out_of_resource_error },
0173 { 487L, busy_error }
0174 #else
0175 { EACCES, security_error },
0176 { EROFS, read_only_error },
0177 { EIO, io_error },
0178 { ENAMETOOLONG, path_error },
0179 { ENOENT, not_found_error },
0180
0181 { EAGAIN, busy_error },
0182 { EBUSY, busy_error },
0183 { ETXTBSY, busy_error },
0184 { EEXIST, already_exists_error },
0185 { ENOTEMPTY, not_empty_error },
0186 { EISDIR, is_directory_error },
0187 { ENOSPC, out_of_space_error },
0188 { ENOMEM, out_of_memory_error },
0189 { EMFILE, out_of_resource_error },
0190 { ENOENT, not_such_file_or_directory },
0191 { EINVAL, invalid_argument }
0192 #endif
0193 };
0194
0195 inline error_code_t lookup_error(native_error_t err)
0196 {
0197 const ec_xlate *cur = &ec_table[0],
0198 *end = cur + sizeof(ec_table)/sizeof(ec_xlate);
0199 for (;cur != end; ++cur ){
0200 if ( err == cur->sys_ec ) return cur->ec;
0201 }
0202 return system_error;
0203 }
0204
0205 struct error_info
0206 {
0207 error_info(error_code_t ec = other_error )
0208 : m_nat(0), m_ec(ec)
0209 {}
0210
0211 error_info(native_error_t sys_err_code)
0212 : m_nat(sys_err_code), m_ec(lookup_error(sys_err_code))
0213 {}
0214
0215 error_info & operator =(error_code_t ec)
0216 {
0217 m_nat = 0;
0218 m_ec = ec;
0219 return *this;
0220 }
0221
0222 error_info & operator =(native_error_t sys_err_code)
0223 {
0224 m_nat = sys_err_code;
0225 m_ec = lookup_error(sys_err_code);
0226 return *this;
0227 }
0228
0229 native_error_t get_native_error()const
0230 { return m_nat; }
0231
0232 error_code_t get_error_code()const
0233 { return m_ec; }
0234
0235 private:
0236 native_error_t m_nat;
0237 error_code_t m_ec;
0238 };
0239 #endif
0240
0241 }
0242 }
0243
0244 #include <boost/interprocess/detail/config_end.hpp>
0245
0246 #endif