1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2008. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 // Parts of this code are taken from boost::filesystem library
11 //////////////////////////////////////////////////////////////////////////////
13 // Copyright (C) 2002 Beman Dawes
14 // Copyright (C) 2001 Dietmar Kuehl
15 // Use, modification, and distribution is subject to the Boost Software
16 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
17 // at http://www.boost.org/LICENSE_1_0.txt)
19 // See library home page at http://www.boost.org/libs/filesystem
21 //////////////////////////////////////////////////////////////////////////////
24 #ifndef BOOST_INTERPROCESS_ERRORS_HPP
25 #define BOOST_INTERPROCESS_ERRORS_HPP
27 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
31 #include <boost/interprocess/detail/config_begin.hpp>
32 #include <boost/interprocess/detail/workaround.hpp>
36 #if (defined BOOST_INTERPROCESS_WINDOWS)
37 # include <boost/interprocess/detail/win32_api.hpp>
39 # ifdef BOOST_HAS_UNISTD_H
40 # include <errno.h> //Errors
41 # include <cstring> //strerror
42 # else //ifdef BOOST_HAS_UNISTD_H
43 # error Unknown platform
44 # endif //ifdef BOOST_HAS_UNISTD_H
45 #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
48 //!Describes the error numbering of interprocess classes
51 namespace interprocess
{
53 static inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
55 #if (defined BOOST_INTERPROCESS_WINDOWS)
56 return winapi::get_last_error();
58 return errno
; // GCC 3.1 won't accept ::errno
63 #if (defined BOOST_INTERPROCESS_WINDOWS)
64 inline void fill_system_message(int sys_err_code
, std::string
&str
)
67 winapi::format_message(
68 winapi::format_message_allocate_buffer
|
69 winapi::format_message_from_system
|
70 winapi::format_message_ignore_inserts
,
73 winapi::make_lang_id(winapi::lang_neutral
, winapi::sublang_default
), // Default language
74 reinterpret_cast<char *>(&lpMsgBuf
),
78 str
+= static_cast<const char*>(lpMsgBuf
);
79 winapi::local_free( lpMsgBuf
); // free the buffer
81 && (str
[str
.size()-1] == '\n' || str
[str
.size()-1] == '\r') )
82 str
.erase( str
.size()-1 );
85 static inline void fill_system_message( int system_error
, std::string
&str
)
86 { str
= std::strerror(system_error
); }
93 system_error
, // system generated error; if possible, is translated
94 // to one of the more specific errors below.
95 other_error
, // library generated error
96 security_error
, // includes access rights, permissions failures
101 // not_directory_error,
102 busy_error
, // implies trying again might succeed
103 already_exists_error
,
108 out_of_resource_error
,
114 not_such_file_or_directory
,
118 typedef int native_error_t
;
123 native_error_t sys_ec
;
127 static const ec_xlate ec_table
[] =
129 #if (defined BOOST_INTERPROCESS_WINDOWS)
130 { /*ERROR_ACCESS_DENIED*/5L, security_error
},
131 { /*ERROR_INVALID_ACCESS*/12L, security_error
},
132 { /*ERROR_SHARING_VIOLATION*/32L, security_error
},
133 { /*ERROR_LOCK_VIOLATION*/33L, security_error
},
134 { /*ERROR_LOCKED*/212L, security_error
},
135 { /*ERROR_NOACCESS*/998L, security_error
},
136 { /*ERROR_WRITE_PROTECT*/19L, read_only_error
},
137 { /*ERROR_NOT_READY*/21L, io_error
},
138 { /*ERROR_SEEK*/25L, io_error
},
139 { /*ERROR_READ_FAULT*/30L, io_error
},
140 { /*ERROR_WRITE_FAULT*/29L, io_error
},
141 { /*ERROR_CANTOPEN*/1011L, io_error
},
142 { /*ERROR_CANTREAD*/1012L, io_error
},
143 { /*ERROR_CANTWRITE*/1013L, io_error
},
144 { /*ERROR_DIRECTORY*/267L, path_error
},
145 { /*ERROR_INVALID_NAME*/123L, path_error
},
146 { /*ERROR_FILE_NOT_FOUND*/2L, not_found_error
},
147 { /*ERROR_PATH_NOT_FOUND*/3L, not_found_error
},
148 { /*ERROR_DEV_NOT_EXIST*/55L, not_found_error
},
149 { /*ERROR_DEVICE_IN_USE*/2404L, busy_error
},
150 { /*ERROR_OPEN_FILES*/2401L, busy_error
},
151 { /*ERROR_BUSY_DRIVE*/142L, busy_error
},
152 { /*ERROR_BUSY*/170L, busy_error
},
153 { /*ERROR_FILE_EXISTS*/80L, already_exists_error
},
154 { /*ERROR_ALREADY_EXISTS*/183L, already_exists_error
},
155 { /*ERROR_DIR_NOT_EMPTY*/145L, not_empty_error
},
156 { /*ERROR_HANDLE_DISK_FULL*/39L, out_of_space_error
},
157 { /*ERROR_DISK_FULL*/112L, out_of_space_error
},
158 { /*ERROR_OUTOFMEMORY*/14L, out_of_memory_error
},
159 { /*ERROR_NOT_ENOUGH_MEMORY*/8L, out_of_memory_error
},
160 { /*ERROR_TOO_MANY_OPEN_FILES*/4L, out_of_resource_error
}
161 #else //#if (defined BOOST_INTERPROCESS_WINDOWS)
162 { EACCES
, security_error
},
163 { EROFS
, read_only_error
},
165 { ENAMETOOLONG
, path_error
},
166 { ENOENT
, not_found_error
},
167 // { ENOTDIR, not_directory_error },
168 { EAGAIN
, busy_error
},
169 { EBUSY
, busy_error
},
170 { ETXTBSY
, busy_error
},
171 { EEXIST
, already_exists_error
},
172 { ENOTEMPTY
, not_empty_error
},
173 { EISDIR
, is_directory_error
},
174 { ENOSPC
, out_of_space_error
},
175 { ENOMEM
, out_of_memory_error
},
176 { EMFILE
, out_of_resource_error
},
177 { ENOENT
, not_such_file_or_directory
},
178 { EINVAL
, invalid_argument
}
179 #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
182 static inline error_code_t
lookup_error(native_error_t err
)
184 const ec_xlate
*cur
= &ec_table
[0],
185 *end
= cur
+ sizeof(ec_table
)/sizeof(ec_xlate
);
186 for (;cur
!= end
; ++cur
){
187 if ( err
== cur
->sys_ec
) return cur
->ec
;
189 return system_error
; // general system error code
194 error_info(error_code_t ec
= other_error
)
198 error_info(native_error_t sys_err_code
)
199 : m_nat(sys_err_code
), m_ec(lookup_error(sys_err_code
))
202 error_info
& operator =(error_code_t ec
)
209 error_info
& operator =(native_error_t sys_err_code
)
211 m_nat
= sys_err_code
;
212 m_ec
= lookup_error(sys_err_code
);
216 native_error_t
get_native_error()const
219 error_code_t
get_error_code()const
223 native_error_t m_nat
;
228 } // namespace interprocess {
231 #include <boost/interprocess/detail/config_end.hpp>
233 #endif // BOOST_INTERPROCESS_ERRORS_HPP