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