Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 08:05:01

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 // Parts of this code are taken from boost::filesystem library
0010 //
0011 //////////////////////////////////////////////////////////////////////////////
0012 //
0013 //  Copyright (C) 2002 Beman Dawes
0014 //  Copyright (C) 2001 Dietmar Kuehl
0015 //  Use, modification, and distribution is subject to the Boost Software
0016 //  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
0017 //  at http://www.boost.org/LICENSE_1_0.txt)
0018 //
0019 //  See library home page at http://www.boost.org/libs/filesystem
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  //ifdef BOOST_HAS_UNISTD_H
0047 #    error Unknown platform
0048 #  endif //ifdef BOOST_HAS_UNISTD_H
0049 #endif   //#if defined (BOOST_INTERPROCESS_WINDOWS)
0050 
0051 //!\file
0052 //!Describes the error numbering of interprocess classes
0053 
0054 namespace boost {
0055 namespace interprocess {
0056 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0057 inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
0058 {
0059    #if defined (BOOST_INTERPROCESS_WINDOWS)
0060    return (int)winapi::get_last_error();
0061    #else
0062    return errno; // GCC 3.1 won't accept ::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), // Default language
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 ); // free the buffer
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0098 
0099 enum error_code_t
0100 {
0101    no_error = 0,
0102    system_error,     // system generated error; if possible, is translated
0103                      // to one of the more specific errors below.
0104    other_error,      // library generated error
0105    security_error,   // includes access rights, permissions failures
0106    read_only_error,
0107    io_error,
0108    path_error,
0109    not_found_error,
0110 //   not_directory_error,
0111    busy_error,       // implies trying again might succeed
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    { /*ERROR_ACCESS_DENIED*/5L, security_error },
0144    { /*ERROR_INVALID_ACCESS*/12L, security_error },
0145    { /*ERROR_SHARING_VIOLATION*/32L, security_error },
0146    { /*ERROR_LOCK_VIOLATION*/33L, security_error },
0147    { /*ERROR_LOCKED*/212L, security_error },
0148    { /*ERROR_NOACCESS*/998L, security_error },
0149    { /*ERROR_WRITE_PROTECT*/19L, read_only_error },
0150    { /*ERROR_NOT_READY*/21L, io_error },
0151    { /*ERROR_SEEK*/25L, io_error },
0152    { /*ERROR_READ_FAULT*/30L, io_error },
0153    { /*ERROR_WRITE_FAULT*/29L, io_error },
0154    { /*ERROR_CANTOPEN*/1011L, io_error },
0155    { /*ERROR_CANTREAD*/1012L, io_error },
0156    { /*ERROR_CANTWRITE*/1013L, io_error },
0157    { /*ERROR_DIRECTORY*/267L, path_error },
0158    { /*ERROR_INVALID_NAME*/123L, path_error },
0159    { /*ERROR_FILE_NOT_FOUND*/2L, not_found_error },
0160    { /*ERROR_PATH_NOT_FOUND*/3L, not_found_error },
0161    { /*ERROR_DEV_NOT_EXIST*/55L, not_found_error },
0162    { /*ERROR_DEVICE_IN_USE*/2404L, busy_error },
0163    { /*ERROR_OPEN_FILES*/2401L, busy_error },
0164    { /*ERROR_BUSY_DRIVE*/142L, busy_error },
0165    { /*ERROR_BUSY*/170L, busy_error },
0166    { /*ERROR_FILE_EXISTS*/80L, already_exists_error },
0167    { /*ERROR_ALREADY_EXISTS*/183L, already_exists_error },
0168    { /*ERROR_DIR_NOT_EMPTY*/145L, not_empty_error },
0169    { /*ERROR_HANDLE_DISK_FULL*/39L, out_of_space_error },
0170    { /*ERROR_DISK_FULL*/112L, out_of_space_error },
0171    { /*ERROR_OUTOFMEMORY*/14L, out_of_memory_error },
0172    { /*ERROR_NOT_ENOUGH_MEMORY*/8L, out_of_memory_error },
0173    { /*ERROR_TOO_MANY_OPEN_FILES*/4L, out_of_resource_error },
0174    { /*ERROR_INVALID_ADDRESS*/487L, busy_error }
0175    #else    //#if defined (BOOST_INTERPROCESS_WINDOWS)
0176    { EACCES, security_error },
0177    { EROFS, read_only_error },
0178    { EIO, io_error },
0179    { ENAMETOOLONG, path_error },
0180    { ENOENT, not_found_error },
0181    //    { ENOTDIR, not_directory_error },
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   //#if defined (BOOST_INTERPROCESS_WINDOWS)
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; // general system error code
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0241 
0242 }  // namespace interprocess {
0243 }  // namespace boost
0244 
0245 #include <boost/interprocess/detail/config_end.hpp>
0246 
0247 #endif // BOOST_INTERPROCESS_ERRORS_HPP