Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:34

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 #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  //ifdef BOOST_HAS_UNISTD_H
0046 #    error Unknown platform
0047 #  endif //ifdef BOOST_HAS_UNISTD_H
0048 #endif   //#if defined (BOOST_INTERPROCESS_WINDOWS)
0049 
0050 //!\file
0051 //!Describes the error numbering of interprocess classes
0052 
0053 namespace boost {
0054 namespace interprocess {
0055 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0056 inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
0057 {
0058    #if defined (BOOST_INTERPROCESS_WINDOWS)
0059    return (int)winapi::get_last_error();
0060    #else
0061    return errno; // GCC 3.1 won't accept ::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), // Default language
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 ); // free the buffer
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0097 
0098 enum error_code_t
0099 {
0100    no_error = 0,
0101    system_error,     // system generated error; if possible, is translated
0102                      // to one of the more specific errors below.
0103    other_error,      // library generated error
0104    security_error,   // includes access rights, permissions failures
0105    read_only_error,
0106    io_error,
0107    path_error,
0108    not_found_error,
0109 //   not_directory_error,
0110    busy_error,       // implies trying again might succeed
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    { /*ERROR_ACCESS_DENIED*/5L, security_error },
0143    { /*ERROR_INVALID_ACCESS*/12L, security_error },
0144    { /*ERROR_SHARING_VIOLATION*/32L, security_error },
0145    { /*ERROR_LOCK_VIOLATION*/33L, security_error },
0146    { /*ERROR_LOCKED*/212L, security_error },
0147    { /*ERROR_NOACCESS*/998L, security_error },
0148    { /*ERROR_WRITE_PROTECT*/19L, read_only_error },
0149    { /*ERROR_NOT_READY*/21L, io_error },
0150    { /*ERROR_SEEK*/25L, io_error },
0151    { /*ERROR_READ_FAULT*/30L, io_error },
0152    { /*ERROR_WRITE_FAULT*/29L, io_error },
0153    { /*ERROR_CANTOPEN*/1011L, io_error },
0154    { /*ERROR_CANTREAD*/1012L, io_error },
0155    { /*ERROR_CANTWRITE*/1013L, io_error },
0156    { /*ERROR_DIRECTORY*/267L, path_error },
0157    { /*ERROR_INVALID_NAME*/123L, path_error },
0158    { /*ERROR_FILE_NOT_FOUND*/2L, not_found_error },
0159    { /*ERROR_PATH_NOT_FOUND*/3L, not_found_error },
0160    { /*ERROR_DEV_NOT_EXIST*/55L, not_found_error },
0161    { /*ERROR_DEVICE_IN_USE*/2404L, busy_error },
0162    { /*ERROR_OPEN_FILES*/2401L, busy_error },
0163    { /*ERROR_BUSY_DRIVE*/142L, busy_error },
0164    { /*ERROR_BUSY*/170L, busy_error },
0165    { /*ERROR_FILE_EXISTS*/80L, already_exists_error },
0166    { /*ERROR_ALREADY_EXISTS*/183L, already_exists_error },
0167    { /*ERROR_DIR_NOT_EMPTY*/145L, not_empty_error },
0168    { /*ERROR_HANDLE_DISK_FULL*/39L, out_of_space_error },
0169    { /*ERROR_DISK_FULL*/112L, out_of_space_error },
0170    { /*ERROR_OUTOFMEMORY*/14L, out_of_memory_error },
0171    { /*ERROR_NOT_ENOUGH_MEMORY*/8L, out_of_memory_error },
0172    { /*ERROR_TOO_MANY_OPEN_FILES*/4L, out_of_resource_error },
0173    { /*ERROR_INVALID_ADDRESS*/487L, busy_error }
0174    #else    //#if defined (BOOST_INTERPROCESS_WINDOWS)
0175    { EACCES, security_error },
0176    { EROFS, read_only_error },
0177    { EIO, io_error },
0178    { ENAMETOOLONG, path_error },
0179    { ENOENT, not_found_error },
0180    //    { ENOTDIR, not_directory_error },
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   //#if defined (BOOST_INTERPROCESS_WINDOWS)
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; // general system error code
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0240 
0241 }  // namespace interprocess {
0242 }  // namespace boost
0243 
0244 #include <boost/interprocess/detail/config_end.hpp>
0245 
0246 #endif // BOOST_INTERPROCESS_ERRORS_HPP