annotate DEPENDENCIES/generic/include/boost/interprocess/errors.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
Chris@16 4 // Software License, Version 1.0. (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 //
Chris@16 7 // See http://www.boost.org/libs/interprocess for documentation.
Chris@16 8 //
Chris@16 9 // Parts of this code are taken from boost::filesystem library
Chris@16 10 //
Chris@16 11 //////////////////////////////////////////////////////////////////////////////
Chris@16 12 //
Chris@16 13 // Copyright (C) 2002 Beman Dawes
Chris@16 14 // Copyright (C) 2001 Dietmar Kuehl
Chris@16 15 // Use, modification, and distribution is subject to the Boost Software
Chris@16 16 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
Chris@16 17 // at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 18 //
Chris@16 19 // See library home page at http://www.boost.org/libs/filesystem
Chris@16 20 //
Chris@16 21 //////////////////////////////////////////////////////////////////////////////
Chris@16 22
Chris@16 23
Chris@16 24 #ifndef BOOST_INTERPROCESS_ERRORS_HPP
Chris@16 25 #define BOOST_INTERPROCESS_ERRORS_HPP
Chris@16 26
Chris@101 27 #ifndef BOOST_CONFIG_HPP
Chris@101 28 # include <boost/config.hpp>
Chris@101 29 #endif
Chris@101 30 #
Chris@101 31 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@16 32 # pragma once
Chris@16 33 #endif
Chris@16 34
Chris@16 35 #include <boost/interprocess/detail/config_begin.hpp>
Chris@16 36 #include <boost/interprocess/detail/workaround.hpp>
Chris@16 37 #include <stdarg.h>
Chris@16 38 #include <string>
Chris@16 39
Chris@101 40 #if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 41 # include <boost/interprocess/detail/win32_api.hpp>
Chris@16 42 #else
Chris@16 43 # ifdef BOOST_HAS_UNISTD_H
Chris@16 44 # include <errno.h> //Errors
Chris@16 45 # include <cstring> //strerror
Chris@16 46 # else //ifdef BOOST_HAS_UNISTD_H
Chris@16 47 # error Unknown platform
Chris@16 48 # endif //ifdef BOOST_HAS_UNISTD_H
Chris@101 49 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 50
Chris@16 51 //!\file
Chris@16 52 //!Describes the error numbering of interprocess classes
Chris@16 53
Chris@16 54 namespace boost {
Chris@16 55 namespace interprocess {
Chris@101 56 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 57 inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
Chris@16 58 {
Chris@101 59 #if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 60 return winapi::get_last_error();
Chris@16 61 #else
Chris@16 62 return errno; // GCC 3.1 won't accept ::errno
Chris@16 63 #endif
Chris@16 64 }
Chris@16 65
Chris@16 66
Chris@101 67 #if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 68 inline void fill_system_message(int sys_err_code, std::string &str)
Chris@16 69 {
Chris@16 70 void *lpMsgBuf;
Chris@16 71 winapi::format_message(
Chris@16 72 winapi::format_message_allocate_buffer |
Chris@16 73 winapi::format_message_from_system |
Chris@16 74 winapi::format_message_ignore_inserts,
Chris@16 75 0,
Chris@16 76 sys_err_code,
Chris@16 77 winapi::make_lang_id(winapi::lang_neutral, winapi::sublang_default), // Default language
Chris@16 78 reinterpret_cast<char *>(&lpMsgBuf),
Chris@16 79 0,
Chris@16 80 0
Chris@16 81 );
Chris@16 82 str += static_cast<const char*>(lpMsgBuf);
Chris@16 83 winapi::local_free( lpMsgBuf ); // free the buffer
Chris@16 84 while ( str.size()
Chris@16 85 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
Chris@16 86 str.erase( str.size()-1 );
Chris@16 87 }
Chris@16 88 # else
Chris@16 89 inline void fill_system_message( int system_error, std::string &str)
Chris@16 90 { str = std::strerror(system_error); }
Chris@16 91 # endif
Chris@101 92 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 93
Chris@16 94 enum error_code_t
Chris@16 95 {
Chris@16 96 no_error = 0,
Chris@16 97 system_error, // system generated error; if possible, is translated
Chris@16 98 // to one of the more specific errors below.
Chris@16 99 other_error, // library generated error
Chris@16 100 security_error, // includes access rights, permissions failures
Chris@16 101 read_only_error,
Chris@16 102 io_error,
Chris@16 103 path_error,
Chris@16 104 not_found_error,
Chris@16 105 // not_directory_error,
Chris@16 106 busy_error, // implies trying again might succeed
Chris@16 107 already_exists_error,
Chris@16 108 not_empty_error,
Chris@16 109 is_directory_error,
Chris@16 110 out_of_space_error,
Chris@16 111 out_of_memory_error,
Chris@16 112 out_of_resource_error,
Chris@16 113 lock_error,
Chris@16 114 sem_error,
Chris@16 115 mode_error,
Chris@16 116 size_error,
Chris@16 117 corrupted_error,
Chris@16 118 not_such_file_or_directory,
Chris@16 119 invalid_argument,
Chris@16 120 timeout_when_locking_error,
Chris@101 121 timeout_when_waiting_error,
Chris@101 122 owner_dead_error
Chris@16 123 };
Chris@16 124
Chris@16 125 typedef int native_error_t;
Chris@16 126
Chris@101 127 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 128 struct ec_xlate
Chris@16 129 {
Chris@16 130 native_error_t sys_ec;
Chris@16 131 error_code_t ec;
Chris@16 132 };
Chris@16 133
Chris@16 134 static const ec_xlate ec_table[] =
Chris@16 135 {
Chris@101 136 #if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 137 { /*ERROR_ACCESS_DENIED*/5L, security_error },
Chris@16 138 { /*ERROR_INVALID_ACCESS*/12L, security_error },
Chris@16 139 { /*ERROR_SHARING_VIOLATION*/32L, security_error },
Chris@16 140 { /*ERROR_LOCK_VIOLATION*/33L, security_error },
Chris@16 141 { /*ERROR_LOCKED*/212L, security_error },
Chris@16 142 { /*ERROR_NOACCESS*/998L, security_error },
Chris@16 143 { /*ERROR_WRITE_PROTECT*/19L, read_only_error },
Chris@16 144 { /*ERROR_NOT_READY*/21L, io_error },
Chris@16 145 { /*ERROR_SEEK*/25L, io_error },
Chris@16 146 { /*ERROR_READ_FAULT*/30L, io_error },
Chris@16 147 { /*ERROR_WRITE_FAULT*/29L, io_error },
Chris@16 148 { /*ERROR_CANTOPEN*/1011L, io_error },
Chris@16 149 { /*ERROR_CANTREAD*/1012L, io_error },
Chris@16 150 { /*ERROR_CANTWRITE*/1013L, io_error },
Chris@16 151 { /*ERROR_DIRECTORY*/267L, path_error },
Chris@16 152 { /*ERROR_INVALID_NAME*/123L, path_error },
Chris@16 153 { /*ERROR_FILE_NOT_FOUND*/2L, not_found_error },
Chris@16 154 { /*ERROR_PATH_NOT_FOUND*/3L, not_found_error },
Chris@16 155 { /*ERROR_DEV_NOT_EXIST*/55L, not_found_error },
Chris@16 156 { /*ERROR_DEVICE_IN_USE*/2404L, busy_error },
Chris@16 157 { /*ERROR_OPEN_FILES*/2401L, busy_error },
Chris@16 158 { /*ERROR_BUSY_DRIVE*/142L, busy_error },
Chris@16 159 { /*ERROR_BUSY*/170L, busy_error },
Chris@16 160 { /*ERROR_FILE_EXISTS*/80L, already_exists_error },
Chris@16 161 { /*ERROR_ALREADY_EXISTS*/183L, already_exists_error },
Chris@16 162 { /*ERROR_DIR_NOT_EMPTY*/145L, not_empty_error },
Chris@16 163 { /*ERROR_HANDLE_DISK_FULL*/39L, out_of_space_error },
Chris@16 164 { /*ERROR_DISK_FULL*/112L, out_of_space_error },
Chris@16 165 { /*ERROR_OUTOFMEMORY*/14L, out_of_memory_error },
Chris@16 166 { /*ERROR_NOT_ENOUGH_MEMORY*/8L, out_of_memory_error },
Chris@16 167 { /*ERROR_TOO_MANY_OPEN_FILES*/4L, out_of_resource_error },
Chris@16 168 { /*ERROR_INVALID_ADDRESS*/487L, busy_error }
Chris@101 169 #else //#if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 170 { EACCES, security_error },
Chris@16 171 { EROFS, read_only_error },
Chris@16 172 { EIO, io_error },
Chris@16 173 { ENAMETOOLONG, path_error },
Chris@16 174 { ENOENT, not_found_error },
Chris@16 175 // { ENOTDIR, not_directory_error },
Chris@16 176 { EAGAIN, busy_error },
Chris@16 177 { EBUSY, busy_error },
Chris@16 178 { ETXTBSY, busy_error },
Chris@16 179 { EEXIST, already_exists_error },
Chris@16 180 { ENOTEMPTY, not_empty_error },
Chris@16 181 { EISDIR, is_directory_error },
Chris@16 182 { ENOSPC, out_of_space_error },
Chris@16 183 { ENOMEM, out_of_memory_error },
Chris@16 184 { EMFILE, out_of_resource_error },
Chris@16 185 { ENOENT, not_such_file_or_directory },
Chris@16 186 { EINVAL, invalid_argument }
Chris@101 187 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
Chris@16 188 };
Chris@16 189
Chris@16 190 inline error_code_t lookup_error(native_error_t err)
Chris@16 191 {
Chris@16 192 const ec_xlate *cur = &ec_table[0],
Chris@16 193 *end = cur + sizeof(ec_table)/sizeof(ec_xlate);
Chris@16 194 for (;cur != end; ++cur ){
Chris@16 195 if ( err == cur->sys_ec ) return cur->ec;
Chris@16 196 }
Chris@16 197 return system_error; // general system error code
Chris@16 198 }
Chris@16 199
Chris@16 200 struct error_info
Chris@16 201 {
Chris@16 202 error_info(error_code_t ec = other_error )
Chris@16 203 : m_nat(0), m_ec(ec)
Chris@16 204 {}
Chris@16 205
Chris@16 206 error_info(native_error_t sys_err_code)
Chris@16 207 : m_nat(sys_err_code), m_ec(lookup_error(sys_err_code))
Chris@16 208 {}
Chris@16 209
Chris@16 210 error_info & operator =(error_code_t ec)
Chris@16 211 {
Chris@16 212 m_nat = 0;
Chris@16 213 m_ec = ec;
Chris@16 214 return *this;
Chris@16 215 }
Chris@16 216
Chris@16 217 error_info & operator =(native_error_t sys_err_code)
Chris@16 218 {
Chris@16 219 m_nat = sys_err_code;
Chris@16 220 m_ec = lookup_error(sys_err_code);
Chris@16 221 return *this;
Chris@16 222 }
Chris@16 223
Chris@16 224 native_error_t get_native_error()const
Chris@16 225 { return m_nat; }
Chris@16 226
Chris@16 227 error_code_t get_error_code()const
Chris@16 228 { return m_ec; }
Chris@16 229
Chris@16 230 private:
Chris@16 231 native_error_t m_nat;
Chris@16 232 error_code_t m_ec;
Chris@16 233 };
Chris@101 234 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 235
Chris@16 236 } // namespace interprocess {
Chris@16 237 } // namespace boost
Chris@16 238
Chris@16 239 #include <boost/interprocess/detail/config_end.hpp>
Chris@16 240
Chris@16 241 #endif // BOOST_INTERPROCESS_ERRORS_HPP