mirror of
https://github.com/boostorg/system.git
synced 2025-12-25 16:28:05 +01:00
Compare commits
31 Commits
feature/wa
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e1ae5bc7a | ||
|
|
7236be0c58 | ||
|
|
776834b723 | ||
|
|
7d6da0ad91 | ||
|
|
999cf08bf5 | ||
|
|
96418c1531 | ||
|
|
717867cf4e | ||
|
|
7e2a02b16d | ||
|
|
b7e3be2798 | ||
|
|
e919caa2b4 | ||
|
|
b951517625 | ||
|
|
ff18f28684 | ||
|
|
96321beb88 | ||
|
|
313982fa52 | ||
|
|
cc2b081a9e | ||
|
|
a93572ab16 | ||
|
|
cc49bc4457 | ||
|
|
6bc7edbfa8 | ||
|
|
c345b86b0a | ||
|
|
13bac420ab | ||
|
|
abc94afdb2 | ||
|
|
867ac5b446 | ||
|
|
d50db54c44 | ||
|
|
72ea1ef846 | ||
|
|
d581eb203e | ||
|
|
3047581c75 | ||
|
|
ddd679e6d7 | ||
|
|
4ec6c99148 | ||
|
|
7b56fd9acf | ||
|
|
b6a447cdde | ||
|
|
83019b5822 |
@@ -7,325 +7,9 @@
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#ifndef BOOST_SYSTEM_CERRNO_HPP
|
||||
#define BOOST_SYSTEM_CERRNO_HPP
|
||||
#ifndef BOOST_CERRNO_HPP_INCLUDED
|
||||
#define BOOST_CERRNO_HPP_INCLUDED
|
||||
|
||||
#include <cerrno>
|
||||
#include <boost/system/detail/cerrno.hpp>
|
||||
|
||||
// supply errno values likely to be missing, particularly on Windows
|
||||
|
||||
#ifndef EAFNOSUPPORT
|
||||
#define EAFNOSUPPORT 9901
|
||||
#endif
|
||||
|
||||
#ifndef EADDRINUSE
|
||||
#define EADDRINUSE 9902
|
||||
#endif
|
||||
|
||||
#ifndef EADDRNOTAVAIL
|
||||
#define EADDRNOTAVAIL 9903
|
||||
#endif
|
||||
|
||||
#ifndef EISCONN
|
||||
#define EISCONN 9904
|
||||
#endif
|
||||
|
||||
#ifndef EBADMSG
|
||||
#define EBADMSG 9905
|
||||
#endif
|
||||
|
||||
#ifndef ECONNABORTED
|
||||
#define ECONNABORTED 9906
|
||||
#endif
|
||||
|
||||
#ifndef EALREADY
|
||||
#define EALREADY 9907
|
||||
#endif
|
||||
|
||||
#ifndef ECONNREFUSED
|
||||
#define ECONNREFUSED 9908
|
||||
#endif
|
||||
|
||||
#ifndef ECONNRESET
|
||||
#define ECONNRESET 9909
|
||||
#endif
|
||||
|
||||
#ifndef EDESTADDRREQ
|
||||
#define EDESTADDRREQ 9910
|
||||
#endif
|
||||
|
||||
#ifndef EHOSTUNREACH
|
||||
#define EHOSTUNREACH 9911
|
||||
#endif
|
||||
|
||||
#ifndef EIDRM
|
||||
#define EIDRM 9912
|
||||
#endif
|
||||
|
||||
#ifndef EMSGSIZE
|
||||
#define EMSGSIZE 9913
|
||||
#endif
|
||||
|
||||
#ifndef ENETDOWN
|
||||
#define ENETDOWN 9914
|
||||
#endif
|
||||
|
||||
#ifndef ENETRESET
|
||||
#define ENETRESET 9915
|
||||
#endif
|
||||
|
||||
#ifndef ENETUNREACH
|
||||
#define ENETUNREACH 9916
|
||||
#endif
|
||||
|
||||
#ifndef ENOBUFS
|
||||
#define ENOBUFS 9917
|
||||
#endif
|
||||
|
||||
#ifndef ENOLINK
|
||||
#define ENOLINK 9918
|
||||
#endif
|
||||
|
||||
#ifndef ENODATA
|
||||
#define ENODATA 9919
|
||||
#endif
|
||||
|
||||
#ifndef ENOMSG
|
||||
#define ENOMSG 9920
|
||||
#endif
|
||||
|
||||
#ifndef ENOPROTOOPT
|
||||
#define ENOPROTOOPT 9921
|
||||
#endif
|
||||
|
||||
#ifndef ENOSR
|
||||
#define ENOSR 9922
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSOCK
|
||||
#define ENOTSOCK 9923
|
||||
#endif
|
||||
|
||||
#ifndef ENOSTR
|
||||
#define ENOSTR 9924
|
||||
#endif
|
||||
|
||||
#ifndef ENOTCONN
|
||||
#define ENOTCONN 9925
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSUP
|
||||
#define ENOTSUP 9926
|
||||
#endif
|
||||
|
||||
#ifndef ECANCELED
|
||||
#define ECANCELED 9927
|
||||
#endif
|
||||
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS 9928
|
||||
#endif
|
||||
|
||||
#ifndef EOPNOTSUPP
|
||||
#define EOPNOTSUPP 9929
|
||||
#endif
|
||||
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK 9930
|
||||
#endif
|
||||
|
||||
#ifndef EOWNERDEAD
|
||||
#define EOWNERDEAD 9931
|
||||
#endif
|
||||
|
||||
#ifndef EPROTO
|
||||
#define EPROTO 9932
|
||||
#endif
|
||||
|
||||
#ifndef EPROTONOSUPPORT
|
||||
#define EPROTONOSUPPORT 9933
|
||||
#endif
|
||||
|
||||
#ifndef ENOTRECOVERABLE
|
||||
#define ENOTRECOVERABLE 9934
|
||||
#endif
|
||||
|
||||
#ifndef ETIME
|
||||
#define ETIME 9935
|
||||
#endif
|
||||
|
||||
#ifndef ETXTBSY
|
||||
#define ETXTBSY 9936
|
||||
#endif
|
||||
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT 9938
|
||||
#endif
|
||||
|
||||
#ifndef ELOOP
|
||||
#define ELOOP 9939
|
||||
#endif
|
||||
|
||||
#ifndef EOVERFLOW
|
||||
#define EOVERFLOW 9940
|
||||
#endif
|
||||
|
||||
#ifndef EPROTOTYPE
|
||||
#define EPROTOTYPE 9941
|
||||
#endif
|
||||
|
||||
#ifndef ENOSYS
|
||||
#define ENOSYS 9942
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
#define EINVAL 9943
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE
|
||||
#define ERANGE 9944
|
||||
#endif
|
||||
|
||||
#ifndef EILSEQ
|
||||
#define EILSEQ 9945
|
||||
#endif
|
||||
|
||||
// Windows Mobile doesn't appear to define these:
|
||||
|
||||
#ifndef E2BIG
|
||||
#define E2BIG 9946
|
||||
#endif
|
||||
|
||||
#ifndef EDOM
|
||||
#define EDOM 9947
|
||||
#endif
|
||||
|
||||
#ifndef EFAULT
|
||||
#define EFAULT 9948
|
||||
#endif
|
||||
|
||||
#ifndef EBADF
|
||||
#define EBADF 9949
|
||||
#endif
|
||||
|
||||
#ifndef EPIPE
|
||||
#define EPIPE 9950
|
||||
#endif
|
||||
|
||||
#ifndef EXDEV
|
||||
#define EXDEV 9951
|
||||
#endif
|
||||
|
||||
#ifndef EBUSY
|
||||
#define EBUSY 9952
|
||||
#endif
|
||||
|
||||
#ifndef ENOTEMPTY
|
||||
#define ENOTEMPTY 9953
|
||||
#endif
|
||||
|
||||
#ifndef ENOEXEC
|
||||
#define ENOEXEC 9954
|
||||
#endif
|
||||
|
||||
#ifndef EEXIST
|
||||
#define EEXIST 9955
|
||||
#endif
|
||||
|
||||
#ifndef EFBIG
|
||||
#define EFBIG 9956
|
||||
#endif
|
||||
|
||||
#ifndef ENAMETOOLONG
|
||||
#define ENAMETOOLONG 9957
|
||||
#endif
|
||||
|
||||
#ifndef ENOTTY
|
||||
#define ENOTTY 9958
|
||||
#endif
|
||||
|
||||
#ifndef EINTR
|
||||
#define EINTR 9959
|
||||
#endif
|
||||
|
||||
#ifndef ESPIPE
|
||||
#define ESPIPE 9960
|
||||
#endif
|
||||
|
||||
#ifndef EIO
|
||||
#define EIO 9961
|
||||
#endif
|
||||
|
||||
#ifndef EISDIR
|
||||
#define EISDIR 9962
|
||||
#endif
|
||||
|
||||
#ifndef ECHILD
|
||||
#define ECHILD 9963
|
||||
#endif
|
||||
|
||||
#ifndef ENOLCK
|
||||
#define ENOLCK 9964
|
||||
#endif
|
||||
|
||||
#ifndef ENOSPC
|
||||
#define ENOSPC 9965
|
||||
#endif
|
||||
|
||||
#ifndef ENXIO
|
||||
#define ENXIO 9966
|
||||
#endif
|
||||
|
||||
#ifndef ENODEV
|
||||
#define ENODEV 9967
|
||||
#endif
|
||||
|
||||
#ifndef ENOENT
|
||||
#define ENOENT 9968
|
||||
#endif
|
||||
|
||||
#ifndef ESRCH
|
||||
#define ESRCH 9969
|
||||
#endif
|
||||
|
||||
#ifndef ENOTDIR
|
||||
#define ENOTDIR 9970
|
||||
#endif
|
||||
|
||||
#ifndef ENOMEM
|
||||
#define ENOMEM 9971
|
||||
#endif
|
||||
|
||||
#ifndef EPERM
|
||||
#define EPERM 9972
|
||||
#endif
|
||||
|
||||
#ifndef EACCES
|
||||
#define EACCES 9973
|
||||
#endif
|
||||
|
||||
#ifndef EROFS
|
||||
#define EROFS 9974
|
||||
#endif
|
||||
|
||||
#ifndef EDEADLK
|
||||
#define EDEADLK 9975
|
||||
#endif
|
||||
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN 9976
|
||||
#endif
|
||||
|
||||
#ifndef ENFILE
|
||||
#define ENFILE 9977
|
||||
#endif
|
||||
|
||||
#ifndef EMFILE
|
||||
#define EMFILE 9978
|
||||
#endif
|
||||
|
||||
#ifndef EMLINK
|
||||
#define EMLINK 9979
|
||||
#endif
|
||||
|
||||
#endif // include guard
|
||||
#endif // #ifndef BOOST_CERRNO_HPP_INCLUDED
|
||||
|
||||
329
include/boost/system/detail/cerrno.hpp
Normal file
329
include/boost/system/detail/cerrno.hpp
Normal file
@@ -0,0 +1,329 @@
|
||||
// Copyright Beman Dawes 2005.
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#ifndef BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
// supply errno values likely to be missing, particularly on Windows
|
||||
|
||||
#ifndef EAFNOSUPPORT
|
||||
#define EAFNOSUPPORT 9901
|
||||
#endif
|
||||
|
||||
#ifndef EADDRINUSE
|
||||
#define EADDRINUSE 9902
|
||||
#endif
|
||||
|
||||
#ifndef EADDRNOTAVAIL
|
||||
#define EADDRNOTAVAIL 9903
|
||||
#endif
|
||||
|
||||
#ifndef EISCONN
|
||||
#define EISCONN 9904
|
||||
#endif
|
||||
|
||||
#ifndef EBADMSG
|
||||
#define EBADMSG 9905
|
||||
#endif
|
||||
|
||||
#ifndef ECONNABORTED
|
||||
#define ECONNABORTED 9906
|
||||
#endif
|
||||
|
||||
#ifndef EALREADY
|
||||
#define EALREADY 9907
|
||||
#endif
|
||||
|
||||
#ifndef ECONNREFUSED
|
||||
#define ECONNREFUSED 9908
|
||||
#endif
|
||||
|
||||
#ifndef ECONNRESET
|
||||
#define ECONNRESET 9909
|
||||
#endif
|
||||
|
||||
#ifndef EDESTADDRREQ
|
||||
#define EDESTADDRREQ 9910
|
||||
#endif
|
||||
|
||||
#ifndef EHOSTUNREACH
|
||||
#define EHOSTUNREACH 9911
|
||||
#endif
|
||||
|
||||
#ifndef EIDRM
|
||||
#define EIDRM 9912
|
||||
#endif
|
||||
|
||||
#ifndef EMSGSIZE
|
||||
#define EMSGSIZE 9913
|
||||
#endif
|
||||
|
||||
#ifndef ENETDOWN
|
||||
#define ENETDOWN 9914
|
||||
#endif
|
||||
|
||||
#ifndef ENETRESET
|
||||
#define ENETRESET 9915
|
||||
#endif
|
||||
|
||||
#ifndef ENETUNREACH
|
||||
#define ENETUNREACH 9916
|
||||
#endif
|
||||
|
||||
#ifndef ENOBUFS
|
||||
#define ENOBUFS 9917
|
||||
#endif
|
||||
|
||||
#ifndef ENOLINK
|
||||
#define ENOLINK 9918
|
||||
#endif
|
||||
|
||||
#ifndef ENODATA
|
||||
#define ENODATA 9919
|
||||
#endif
|
||||
|
||||
#ifndef ENOMSG
|
||||
#define ENOMSG 9920
|
||||
#endif
|
||||
|
||||
#ifndef ENOPROTOOPT
|
||||
#define ENOPROTOOPT 9921
|
||||
#endif
|
||||
|
||||
#ifndef ENOSR
|
||||
#define ENOSR 9922
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSOCK
|
||||
#define ENOTSOCK 9923
|
||||
#endif
|
||||
|
||||
#ifndef ENOSTR
|
||||
#define ENOSTR 9924
|
||||
#endif
|
||||
|
||||
#ifndef ENOTCONN
|
||||
#define ENOTCONN 9925
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSUP
|
||||
#define ENOTSUP 9926
|
||||
#endif
|
||||
|
||||
#ifndef ECANCELED
|
||||
#define ECANCELED 9927
|
||||
#endif
|
||||
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS 9928
|
||||
#endif
|
||||
|
||||
#ifndef EOPNOTSUPP
|
||||
#define EOPNOTSUPP 9929
|
||||
#endif
|
||||
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK 9930
|
||||
#endif
|
||||
|
||||
#ifndef EOWNERDEAD
|
||||
#define EOWNERDEAD 9931
|
||||
#endif
|
||||
|
||||
#ifndef EPROTO
|
||||
#define EPROTO 9932
|
||||
#endif
|
||||
|
||||
#ifndef EPROTONOSUPPORT
|
||||
#define EPROTONOSUPPORT 9933
|
||||
#endif
|
||||
|
||||
#ifndef ENOTRECOVERABLE
|
||||
#define ENOTRECOVERABLE 9934
|
||||
#endif
|
||||
|
||||
#ifndef ETIME
|
||||
#define ETIME 9935
|
||||
#endif
|
||||
|
||||
#ifndef ETXTBSY
|
||||
#define ETXTBSY 9936
|
||||
#endif
|
||||
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT 9938
|
||||
#endif
|
||||
|
||||
#ifndef ELOOP
|
||||
#define ELOOP 9939
|
||||
#endif
|
||||
|
||||
#ifndef EOVERFLOW
|
||||
#define EOVERFLOW 9940
|
||||
#endif
|
||||
|
||||
#ifndef EPROTOTYPE
|
||||
#define EPROTOTYPE 9941
|
||||
#endif
|
||||
|
||||
#ifndef ENOSYS
|
||||
#define ENOSYS 9942
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
#define EINVAL 9943
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE
|
||||
#define ERANGE 9944
|
||||
#endif
|
||||
|
||||
#ifndef EILSEQ
|
||||
#define EILSEQ 9945
|
||||
#endif
|
||||
|
||||
// Windows Mobile doesn't appear to define these:
|
||||
|
||||
#ifndef E2BIG
|
||||
#define E2BIG 9946
|
||||
#endif
|
||||
|
||||
#ifndef EDOM
|
||||
#define EDOM 9947
|
||||
#endif
|
||||
|
||||
#ifndef EFAULT
|
||||
#define EFAULT 9948
|
||||
#endif
|
||||
|
||||
#ifndef EBADF
|
||||
#define EBADF 9949
|
||||
#endif
|
||||
|
||||
#ifndef EPIPE
|
||||
#define EPIPE 9950
|
||||
#endif
|
||||
|
||||
#ifndef EXDEV
|
||||
#define EXDEV 9951
|
||||
#endif
|
||||
|
||||
#ifndef EBUSY
|
||||
#define EBUSY 9952
|
||||
#endif
|
||||
|
||||
#ifndef ENOTEMPTY
|
||||
#define ENOTEMPTY 9953
|
||||
#endif
|
||||
|
||||
#ifndef ENOEXEC
|
||||
#define ENOEXEC 9954
|
||||
#endif
|
||||
|
||||
#ifndef EEXIST
|
||||
#define EEXIST 9955
|
||||
#endif
|
||||
|
||||
#ifndef EFBIG
|
||||
#define EFBIG 9956
|
||||
#endif
|
||||
|
||||
#ifndef ENAMETOOLONG
|
||||
#define ENAMETOOLONG 9957
|
||||
#endif
|
||||
|
||||
#ifndef ENOTTY
|
||||
#define ENOTTY 9958
|
||||
#endif
|
||||
|
||||
#ifndef EINTR
|
||||
#define EINTR 9959
|
||||
#endif
|
||||
|
||||
#ifndef ESPIPE
|
||||
#define ESPIPE 9960
|
||||
#endif
|
||||
|
||||
#ifndef EIO
|
||||
#define EIO 9961
|
||||
#endif
|
||||
|
||||
#ifndef EISDIR
|
||||
#define EISDIR 9962
|
||||
#endif
|
||||
|
||||
#ifndef ECHILD
|
||||
#define ECHILD 9963
|
||||
#endif
|
||||
|
||||
#ifndef ENOLCK
|
||||
#define ENOLCK 9964
|
||||
#endif
|
||||
|
||||
#ifndef ENOSPC
|
||||
#define ENOSPC 9965
|
||||
#endif
|
||||
|
||||
#ifndef ENXIO
|
||||
#define ENXIO 9966
|
||||
#endif
|
||||
|
||||
#ifndef ENODEV
|
||||
#define ENODEV 9967
|
||||
#endif
|
||||
|
||||
#ifndef ENOENT
|
||||
#define ENOENT 9968
|
||||
#endif
|
||||
|
||||
#ifndef ESRCH
|
||||
#define ESRCH 9969
|
||||
#endif
|
||||
|
||||
#ifndef ENOTDIR
|
||||
#define ENOTDIR 9970
|
||||
#endif
|
||||
|
||||
#ifndef ENOMEM
|
||||
#define ENOMEM 9971
|
||||
#endif
|
||||
|
||||
#ifndef EPERM
|
||||
#define EPERM 9972
|
||||
#endif
|
||||
|
||||
#ifndef EACCES
|
||||
#define EACCES 9973
|
||||
#endif
|
||||
|
||||
#ifndef EROFS
|
||||
#define EROFS 9974
|
||||
#endif
|
||||
|
||||
#ifndef EDEADLK
|
||||
#define EDEADLK 9975
|
||||
#endif
|
||||
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN 9976
|
||||
#endif
|
||||
|
||||
#ifndef ENFILE
|
||||
#define ENFILE 9977
|
||||
#endif
|
||||
|
||||
#ifndef EMFILE
|
||||
#define EMFILE 9978
|
||||
#endif
|
||||
|
||||
#ifndef EMLINK
|
||||
#define EMLINK 9979
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED
|
||||
32
include/boost/system/detail/enable_if.hpp
Normal file
32
include/boost/system/detail/enable_if.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<bool C, class T = void> struct enable_if
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T> struct enable_if<false, T>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
|
||||
126
include/boost/system/detail/errc.hpp
Normal file
126
include/boost/system/detail/errc.hpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018, 2020
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/is_error_condition_enum.hpp>
|
||||
#include <boost/system/detail/cerrno.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace errc
|
||||
{
|
||||
|
||||
enum errc_t
|
||||
{
|
||||
success = 0,
|
||||
address_family_not_supported = EAFNOSUPPORT,
|
||||
address_in_use = EADDRINUSE,
|
||||
address_not_available = EADDRNOTAVAIL,
|
||||
already_connected = EISCONN,
|
||||
argument_list_too_long = E2BIG,
|
||||
argument_out_of_domain = EDOM,
|
||||
bad_address = EFAULT,
|
||||
bad_file_descriptor = EBADF,
|
||||
bad_message = EBADMSG,
|
||||
broken_pipe = EPIPE,
|
||||
connection_aborted = ECONNABORTED,
|
||||
connection_already_in_progress = EALREADY,
|
||||
connection_refused = ECONNREFUSED,
|
||||
connection_reset = ECONNRESET,
|
||||
cross_device_link = EXDEV,
|
||||
destination_address_required = EDESTADDRREQ,
|
||||
device_or_resource_busy = EBUSY,
|
||||
directory_not_empty = ENOTEMPTY,
|
||||
executable_format_error = ENOEXEC,
|
||||
file_exists = EEXIST,
|
||||
file_too_large = EFBIG,
|
||||
filename_too_long = ENAMETOOLONG,
|
||||
function_not_supported = ENOSYS,
|
||||
host_unreachable = EHOSTUNREACH,
|
||||
identifier_removed = EIDRM,
|
||||
illegal_byte_sequence = EILSEQ,
|
||||
inappropriate_io_control_operation = ENOTTY,
|
||||
interrupted = EINTR,
|
||||
invalid_argument = EINVAL,
|
||||
invalid_seek = ESPIPE,
|
||||
io_error = EIO,
|
||||
is_a_directory = EISDIR,
|
||||
message_size = EMSGSIZE,
|
||||
network_down = ENETDOWN,
|
||||
network_reset = ENETRESET,
|
||||
network_unreachable = ENETUNREACH,
|
||||
no_buffer_space = ENOBUFS,
|
||||
no_child_process = ECHILD,
|
||||
no_link = ENOLINK,
|
||||
no_lock_available = ENOLCK,
|
||||
no_message_available = ENODATA,
|
||||
no_message = ENOMSG,
|
||||
no_protocol_option = ENOPROTOOPT,
|
||||
no_space_on_device = ENOSPC,
|
||||
no_stream_resources = ENOSR,
|
||||
no_such_device_or_address = ENXIO,
|
||||
no_such_device = ENODEV,
|
||||
no_such_file_or_directory = ENOENT,
|
||||
no_such_process = ESRCH,
|
||||
not_a_directory = ENOTDIR,
|
||||
not_a_socket = ENOTSOCK,
|
||||
not_a_stream = ENOSTR,
|
||||
not_connected = ENOTCONN,
|
||||
not_enough_memory = ENOMEM,
|
||||
not_supported = ENOTSUP,
|
||||
operation_canceled = ECANCELED,
|
||||
operation_in_progress = EINPROGRESS,
|
||||
operation_not_permitted = EPERM,
|
||||
operation_not_supported = EOPNOTSUPP,
|
||||
operation_would_block = EWOULDBLOCK,
|
||||
owner_dead = EOWNERDEAD,
|
||||
permission_denied = EACCES,
|
||||
protocol_error = EPROTO,
|
||||
protocol_not_supported = EPROTONOSUPPORT,
|
||||
read_only_file_system = EROFS,
|
||||
resource_deadlock_would_occur = EDEADLK,
|
||||
resource_unavailable_try_again = EAGAIN,
|
||||
result_out_of_range = ERANGE,
|
||||
state_not_recoverable = ENOTRECOVERABLE,
|
||||
stream_timeout = ETIME,
|
||||
text_file_busy = ETXTBSY,
|
||||
timed_out = ETIMEDOUT,
|
||||
too_many_files_open_in_system = ENFILE,
|
||||
too_many_files_open = EMFILE,
|
||||
too_many_links = EMLINK,
|
||||
too_many_symbolic_link_levels = ELOOP,
|
||||
value_too_large = EOVERFLOW,
|
||||
wrong_protocol_type = EPROTOTYPE
|
||||
};
|
||||
|
||||
} // namespace errc
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
namespace posix = errc;
|
||||
namespace posix_error = errc;
|
||||
|
||||
#endif
|
||||
|
||||
template<> struct is_error_condition_enum<errc::errc_t>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED
|
||||
189
include/boost/system/detail/error_category.hpp
Normal file
189
include/boost/system/detail/error_category.hpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
# include <system_error>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_category;
|
||||
class error_code;
|
||||
class error_condition;
|
||||
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed_impl( int ev, error_category const & cat );
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
std::error_category const & to_std_category( error_category const & cat );
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE error_category
|
||||
{
|
||||
private:
|
||||
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool detail::failed_impl( int ev, error_category const & cat );
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
friend std::error_category const & detail::to_std_category( error_category const & cat );
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
|
||||
error_category( error_category const & ) = delete;
|
||||
error_category& operator=( error_category const & ) = delete;
|
||||
|
||||
#else
|
||||
private:
|
||||
|
||||
error_category( error_category const & );
|
||||
error_category& operator=( error_category const & );
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
boost::ulong_long_type id_;
|
||||
|
||||
protected:
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
|
||||
|
||||
~error_category() = default;
|
||||
|
||||
#else
|
||||
|
||||
// We'd like to make the destructor protected, to make code that deletes
|
||||
// an error_category* not compile; unfortunately, doing the below makes
|
||||
// the destructor user-provided and hence breaks use after main, as the
|
||||
// categories may get destroyed before code that uses them
|
||||
|
||||
// ~error_category() {}
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id )
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT = 0;
|
||||
|
||||
virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual std::string message( int ev ) const = 0;
|
||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual bool failed( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return rhs.id_ == 0? this == &rhs: id_ == rhs.id_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!=( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator<( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( id_ < rhs.id_ )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( id_ > rhs.id_ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( rhs.id_ != 0 )
|
||||
{
|
||||
return false; // equal
|
||||
}
|
||||
|
||||
return std::less<error_category const *>()( this, &rhs );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_category const & () const;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
static const boost::ulong_long_type generic_category_id = ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D;
|
||||
static const boost::ulong_long_type system_category_id = ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
if( cat.id_ == system_category_id || cat.id_ == generic_category_id )
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED
|
||||
108
include/boost/system/detail/error_category_impl.hpp
Normal file
108
include/boost/system/detail/error_category_impl.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// error_category default implementation
|
||||
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::string m = this->message( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
std::strncpy( buffer, m.c_str(), len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
return "Message text unavailable";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// interoperability with std::error_code, std::error_condition
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#include <boost/system/detail/to_std_category.hpp>
|
||||
|
||||
inline boost::system::error_category::operator std::error_category const & () const
|
||||
{
|
||||
return boost::system::detail::to_std_category( *this );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
215
include/boost/system/detail/error_code.hpp
Normal file
215
include/boost/system/detail/error_code.hpp
Normal file
@@ -0,0 +1,215 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/system_category.hpp>
|
||||
#include <boost/system/detail/enable_if.hpp>
|
||||
#include <boost/system/is_error_code_enum.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// class error_code
|
||||
|
||||
// We want error_code to be a value type that can be copied without slicing
|
||||
// and without requiring heap allocation, but we also want it to have
|
||||
// polymorphic behavior based on the error category. This is achieved by
|
||||
// abstract base class error_category supplying the polymorphic behavior,
|
||||
// and error_code containing a pointer to an object of a type derived
|
||||
// from error_category.
|
||||
|
||||
class error_code
|
||||
{
|
||||
private:
|
||||
|
||||
int val_;
|
||||
bool failed_;
|
||||
const error_category * cat_;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
|
||||
val_( 0 ), failed_( false ), cat_( &system_category() )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( e );
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = val;
|
||||
failed_ = detail::failed_impl( val, cat );
|
||||
cat_ = &cat;
|
||||
}
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
|
||||
operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = 0;
|
||||
failed_ = false;
|
||||
cat_ = &system_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *cat_;
|
||||
}
|
||||
|
||||
error_condition default_error_condition() const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->default_error_condition( value() );
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
}
|
||||
|
||||
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return !failed_;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_code () const
|
||||
{
|
||||
return std::error_code( value(), category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template<class Ch, class Tr>
|
||||
inline std::basic_ostream<Ch, Tr>&
|
||||
operator<< (std::basic_ostream<Ch, Tr>& os, error_code const & ec)
|
||||
{
|
||||
os << ec.category().name() << ':' << ec.value();
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::size_t hash_value( error_code const & ec )
|
||||
{
|
||||
error_category const & cat = ec.category();
|
||||
|
||||
boost::ulong_long_type id_ = cat.id_;
|
||||
|
||||
if( id_ == 0 )
|
||||
{
|
||||
id_ = reinterpret_cast<boost::uintptr_t>( &cat );
|
||||
}
|
||||
|
||||
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
|
||||
boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
|
||||
|
||||
// id
|
||||
|
||||
hv ^= id_;
|
||||
hv *= prime;
|
||||
|
||||
// value
|
||||
|
||||
hv ^= static_cast<unsigned>( ec.value() );
|
||||
hv *= prime;
|
||||
|
||||
return static_cast<std::size_t>( hv );
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
|
||||
166
include/boost/system/detail/error_condition.hpp
Normal file
166
include/boost/system/detail/error_condition.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <boost/system/detail/enable_if.hpp>
|
||||
#include <boost/system/is_error_condition_enum.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// class error_condition
|
||||
|
||||
// error_conditions are portable, error_codes are system or library specific
|
||||
|
||||
class error_condition
|
||||
{
|
||||
private:
|
||||
|
||||
int val_;
|
||||
bool failed_;
|
||||
error_category const * cat_;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT:
|
||||
val_( 0 ), failed_( false ), cat_( &generic_category() )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
|
||||
typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( e );
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = val;
|
||||
failed_ = detail::failed_impl( val, cat );
|
||||
cat_ = &cat;
|
||||
}
|
||||
|
||||
template<typename ErrorConditionEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
|
||||
operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = 0;
|
||||
failed_ = false;
|
||||
cat_ = &generic_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *cat_;
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
}
|
||||
|
||||
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return !failed_;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_condition () const
|
||||
{
|
||||
return std::error_condition( value(), category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED
|
||||
@@ -1,13 +1,19 @@
|
||||
// Implementation details of generic_error_category
|
||||
//
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
#ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
|
||||
#include <cstring>
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/generic_category_message.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -18,84 +24,100 @@ namespace system
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
// generic_error_category
|
||||
|
||||
// glibc has two incompatible strerror_r definitions
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
inline char const * strerror_r_helper( char const * r, char const * ) BOOST_NOEXCEPT
|
||||
class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
|
||||
{
|
||||
return r;
|
||||
}
|
||||
public:
|
||||
|
||||
inline char const * strerror_r_helper( int r, char const * buffer ) BOOST_NOEXCEPT
|
||||
{
|
||||
return r == 0? buffer: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
|
||||
}
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
char buffer[ 128 ];
|
||||
return generic_error_category_message( ev, buffer, sizeof( buffer ) );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// std::strerror is thread-safe on everything else, incl. Windows
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
char const * m = std::strerror( ev );
|
||||
return m? m: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
|
||||
error_category( detail::generic_category_id )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
return "generic";
|
||||
}
|
||||
|
||||
char const * m = std::strerror( ev );
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
if( m == 0 ) return "Unknown error";
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
std::strncpy( buffer, m, len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
// generic_error_category::message
|
||||
|
||||
return buffer;
|
||||
inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
inline std::string generic_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// generic_category()
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct BOOST_SYMBOL_VISIBLE generic_cat_holder
|
||||
{
|
||||
static constexpr generic_error_category instance{};
|
||||
};
|
||||
|
||||
// Before C++17 it was mandatory to redeclare all static constexpr
|
||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||
template<class T> constexpr generic_error_category generic_cat_holder<T>::instance;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::generic_cat_holder<void>::instance;
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
// deprecated synonyms
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
inline const error_category & get_generic_category() { return generic_category(); }
|
||||
inline const error_category & get_posix_category() { return generic_category(); }
|
||||
static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category();
|
||||
static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category();
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
|
||||
108
include/boost/system/detail/generic_category_message.hpp
Normal file
108
include/boost/system/detail/generic_category_message.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED
|
||||
|
||||
// Implementation of generic_error_category_message
|
||||
//
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
|
||||
// glibc has two incompatible strerror_r definitions
|
||||
|
||||
inline char const * strerror_r_helper( char const * r, char const * ) BOOST_NOEXCEPT
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
inline char const * strerror_r_helper( int r, char const * buffer ) BOOST_NOEXCEPT
|
||||
{
|
||||
return r == 0? buffer: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
|
||||
}
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
char buffer[ 128 ];
|
||||
return generic_error_category_message( ev, buffer, sizeof( buffer ) );
|
||||
}
|
||||
|
||||
#else // #if defined(__GLIBC__)
|
||||
|
||||
// std::strerror is thread-safe on everything else, incl. Windows
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
char const * m = std::strerror( ev );
|
||||
return m? m: "Unknown error";
|
||||
}
|
||||
|
||||
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char const * m = std::strerror( ev );
|
||||
|
||||
if( m == 0 ) return "Unknown error";
|
||||
|
||||
std::strncpy( buffer, m, len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
#endif // #if defined(__GLIBC__)
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED
|
||||
@@ -1,5 +1,6 @@
|
||||
// POSIX-specific implementation details of system_error_category
|
||||
//
|
||||
#ifndef BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
@@ -7,6 +8,8 @@
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -113,20 +116,10 @@ inline bool is_generic_value( int ev ) BOOST_NOEXCEPT
|
||||
return false;
|
||||
}
|
||||
|
||||
inline error_condition system_category_default_error_condition_posix( int ev ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( is_generic_value( ev ) )
|
||||
{
|
||||
return error_condition( ev, generic_category() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return error_condition( ev, system_category() );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_IS_GENERIC_VALUE_HPP_INCLUDED
|
||||
110
include/boost/system/detail/system_category.hpp
Normal file
110
include/boost/system/detail/system_category.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// system_error_category
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
|
||||
error_category( detail::system_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
return "system";
|
||||
}
|
||||
|
||||
error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// system_category()
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct BOOST_SYMBOL_VISIBLE system_cat_holder
|
||||
{
|
||||
static constexpr system_error_category instance{};
|
||||
};
|
||||
|
||||
// Before C++17 it was mandatory to redeclare all static constexpr
|
||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||
template<class T> constexpr system_error_category system_cat_holder<T>::instance;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::system_cat_holder<void>::instance;
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
// deprecated synonyms
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
inline const error_category & get_system_category() { return system_category(); }
|
||||
static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category();
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
146
include/boost/system/detail/system_category_condition_win32.hpp
Normal file
146
include/boost/system/detail/system_category_condition_win32.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright (c) Microsoft Corporation 2014
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
#include <boost/winapi/error_codes.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
{
|
||||
// When using the Windows Runtime, most system errors are reported as HRESULTs.
|
||||
// We want to map the common Win32 errors to their equivalent error condition,
|
||||
// whether or not they are reported via an HRESULT.
|
||||
|
||||
#define BOOST_SYSTEM_FAILED(hr) ((hr) < 0)
|
||||
#define BOOST_SYSTEM_HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
|
||||
#define BOOST_SYSTEM_HRESULT_CODE(hr) ((hr) & 0xFFFF)
|
||||
#define BOOST_SYSTEM_FACILITY_WIN32 7
|
||||
|
||||
if( BOOST_SYSTEM_FAILED( ev ) && BOOST_SYSTEM_HRESULT_FACILITY( ev ) == BOOST_SYSTEM_FACILITY_WIN32 )
|
||||
{
|
||||
ev = BOOST_SYSTEM_HRESULT_CODE( ev );
|
||||
}
|
||||
|
||||
#undef BOOST_SYSTEM_FAILED
|
||||
#undef BOOST_SYSTEM_HRESULT_FACILITY
|
||||
#undef BOOST_SYSTEM_HRESULT_CODE
|
||||
#undef BOOST_SYSTEM_FACILITY_WIN32
|
||||
|
||||
using namespace boost::winapi;
|
||||
using namespace errc;
|
||||
|
||||
// Windows system -> posix_errno decode table
|
||||
// see WinError.h comments for descriptions of errors
|
||||
|
||||
switch ( ev )
|
||||
{
|
||||
case 0: return success;
|
||||
|
||||
case ERROR_ACCESS_DENIED_: return permission_denied;
|
||||
case ERROR_ALREADY_EXISTS_: return file_exists;
|
||||
case ERROR_BAD_UNIT_: return no_such_device;
|
||||
case ERROR_BUFFER_OVERFLOW_: return filename_too_long;
|
||||
case ERROR_BUSY_: return device_or_resource_busy;
|
||||
case ERROR_BUSY_DRIVE_: return device_or_resource_busy;
|
||||
case ERROR_CANNOT_MAKE_: return permission_denied;
|
||||
case ERROR_CANTOPEN_: return io_error;
|
||||
case ERROR_CANTREAD_: return io_error;
|
||||
case ERROR_CANTWRITE_: return io_error;
|
||||
case ERROR_CONNECTION_ABORTED_: return connection_aborted;
|
||||
case ERROR_CURRENT_DIRECTORY_: return permission_denied;
|
||||
case ERROR_DEV_NOT_EXIST_: return no_such_device;
|
||||
case ERROR_DEVICE_IN_USE_: return device_or_resource_busy;
|
||||
case ERROR_DIR_NOT_EMPTY_: return directory_not_empty;
|
||||
case ERROR_DIRECTORY_: return invalid_argument; // WinError.h: "The directory name is invalid"
|
||||
case ERROR_DISK_FULL_: return no_space_on_device;
|
||||
case ERROR_FILE_EXISTS_: return file_exists;
|
||||
case ERROR_FILE_NOT_FOUND_: return no_such_file_or_directory;
|
||||
case ERROR_HANDLE_DISK_FULL_: return no_space_on_device;
|
||||
case ERROR_INVALID_ACCESS_: return permission_denied;
|
||||
case ERROR_INVALID_DRIVE_: return no_such_device;
|
||||
case ERROR_INVALID_FUNCTION_: return function_not_supported;
|
||||
case ERROR_INVALID_HANDLE_: return invalid_argument;
|
||||
case ERROR_INVALID_NAME_: return invalid_argument;
|
||||
case ERROR_LOCK_VIOLATION_: return no_lock_available;
|
||||
case ERROR_LOCKED_: return no_lock_available;
|
||||
case ERROR_NEGATIVE_SEEK_: return invalid_argument;
|
||||
case ERROR_NOACCESS_: return permission_denied;
|
||||
case ERROR_NOT_ENOUGH_MEMORY_: return not_enough_memory;
|
||||
case ERROR_NOT_READY_: return resource_unavailable_try_again;
|
||||
case ERROR_NOT_SAME_DEVICE_: return cross_device_link;
|
||||
case ERROR_OPEN_FAILED_: return io_error;
|
||||
case ERROR_OPEN_FILES_: return device_or_resource_busy;
|
||||
case ERROR_OPERATION_ABORTED_: return operation_canceled;
|
||||
case ERROR_OUTOFMEMORY_: return not_enough_memory;
|
||||
case ERROR_PATH_NOT_FOUND_: return no_such_file_or_directory;
|
||||
case ERROR_READ_FAULT_: return io_error;
|
||||
case ERROR_RETRY_: return resource_unavailable_try_again;
|
||||
case ERROR_SEEK_: return io_error;
|
||||
case ERROR_SHARING_VIOLATION_: return permission_denied;
|
||||
case ERROR_TOO_MANY_OPEN_FILES_: return too_many_files_open;
|
||||
case ERROR_WRITE_FAULT_: return io_error;
|
||||
case ERROR_WRITE_PROTECT_: return permission_denied;
|
||||
|
||||
case WSAEACCES_: return permission_denied;
|
||||
case WSAEADDRINUSE_: return address_in_use;
|
||||
case WSAEADDRNOTAVAIL_: return address_not_available;
|
||||
case WSAEAFNOSUPPORT_: return address_family_not_supported;
|
||||
case WSAEALREADY_: return connection_already_in_progress;
|
||||
case WSAEBADF_: return bad_file_descriptor;
|
||||
case WSAECONNABORTED_: return connection_aborted;
|
||||
case WSAECONNREFUSED_: return connection_refused;
|
||||
case WSAECONNRESET_: return connection_reset;
|
||||
case WSAEDESTADDRREQ_: return destination_address_required;
|
||||
case WSAEFAULT_: return bad_address;
|
||||
case WSAEHOSTUNREACH_: return host_unreachable;
|
||||
case WSAEINPROGRESS_: return operation_in_progress;
|
||||
case WSAEINTR_: return interrupted;
|
||||
case WSAEINVAL_: return invalid_argument;
|
||||
case WSAEISCONN_: return already_connected;
|
||||
case WSAEMFILE_: return too_many_files_open;
|
||||
case WSAEMSGSIZE_: return message_size;
|
||||
case WSAENAMETOOLONG_: return filename_too_long;
|
||||
case WSAENETDOWN_: return network_down;
|
||||
case WSAENETRESET_: return network_reset;
|
||||
case WSAENETUNREACH_: return network_unreachable;
|
||||
case WSAENOBUFS_: return no_buffer_space;
|
||||
case WSAENOPROTOOPT_: return no_protocol_option;
|
||||
case WSAENOTCONN_: return not_connected;
|
||||
case WSAENOTSOCK_: return not_a_socket;
|
||||
case WSAEOPNOTSUPP_: return operation_not_supported;
|
||||
case WSAEPROTONOSUPPORT_: return protocol_not_supported;
|
||||
case WSAEPROTOTYPE_: return wrong_protocol_type;
|
||||
case WSAETIMEDOUT_: return timed_out;
|
||||
case WSAEWOULDBLOCK_: return operation_would_block;
|
||||
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED
|
||||
83
include/boost/system/detail/system_category_impl.hpp
Normal file
83
include/boost/system/detail/system_category_impl.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018, 2020
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/system_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <boost/system/api_config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
|
||||
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
|
||||
#endif
|
||||
|
||||
// system_error_category implementation
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/system_category_message_win32.hpp>
|
||||
#include <boost/system/detail/system_category_condition_win32.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
int e2 = system_category_condition_win32( ev );
|
||||
|
||||
if( e2 == -1 )
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
else
|
||||
{
|
||||
return error_condition( e2, generic_category() );
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return system_category_message_win32( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/generic_category_message.hpp>
|
||||
#include <boost/system/detail/is_generic_value.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( is_generic_value( ev ) )
|
||||
{
|
||||
return error_condition( ev, generic_category() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
|
||||
233
include/boost/system/detail/system_category_message_win32.hpp
Normal file
233
include/boost/system/detail/system_category_message_win32.hpp
Normal file
@@ -0,0 +1,233 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright (c) Microsoft Corporation 2014
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/winapi/error_handling.hpp>
|
||||
#include <boost/winapi/character_code_conversion.hpp>
|
||||
#include <boost/winapi/local_memory.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# endif
|
||||
|
||||
_snprintf( buffer, len - 1, "Unknown error (%d)", ev );
|
||||
|
||||
buffer[ len - 1 ] = 0;
|
||||
return buffer;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
std::snprintf( buffer, len, "Unknown error (%d)", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline boost::winapi::UINT_ message_cp_win32()
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_USE_UTF8)
|
||||
|
||||
return boost::winapi::CP_UTF8_;
|
||||
|
||||
#else
|
||||
|
||||
return boost::winapi::CP_ACP_;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
boost::winapi::UINT_ const code_page = message_cp_win32();
|
||||
|
||||
int r = 0;
|
||||
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
|
||||
if( code_page == boost::winapi::CP_ACP_ )
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
buffer,
|
||||
static_cast<DWORD_>( len ),
|
||||
NULL
|
||||
);
|
||||
|
||||
r = static_cast<int>( retval );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
wchar_t * lpMsgBuf = 0;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
if( retval != 0 )
|
||||
{
|
||||
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, buffer, static_cast<int>( len ), NULL, NULL );
|
||||
boost::winapi::LocalFree( lpMsgBuf );
|
||||
if ( r != 0 ) --r; // exclude null terminator
|
||||
}
|
||||
}
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
|
||||
{
|
||||
buffer[ --r ] = 0;
|
||||
}
|
||||
|
||||
if( r > 0 && buffer[ r-1 ] == '.' )
|
||||
{
|
||||
buffer[ --r ] = 0;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
struct local_free
|
||||
{
|
||||
void * p_;
|
||||
|
||||
~local_free()
|
||||
{
|
||||
boost::winapi::LocalFree( p_ );
|
||||
}
|
||||
};
|
||||
|
||||
inline std::string unknown_message_win32( int ev )
|
||||
{
|
||||
char buffer[ 38 ];
|
||||
return unknown_message_win32( ev, buffer, sizeof( buffer ) );
|
||||
}
|
||||
|
||||
inline std::string system_category_message_win32( int ev )
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
wchar_t * lpMsgBuf = 0;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
if( retval == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
local_free lf_ = { lpMsgBuf };
|
||||
(void)lf_;
|
||||
|
||||
UINT_ const code_page = message_cp_win32();
|
||||
|
||||
int r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, 0, 0, NULL, NULL );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
std::string buffer( r, char() );
|
||||
|
||||
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
--r; // exclude null terminator
|
||||
|
||||
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
if( r > 0 && buffer[ r-1 ] == '.' )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
buffer.resize( r );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED
|
||||
@@ -1,341 +0,0 @@
|
||||
// Windows implementation of system_error_category
|
||||
//
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright (c) Microsoft Corporation 2014
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/winapi/error_codes.hpp>
|
||||
#include <boost/winapi/error_handling.hpp>
|
||||
#include <boost/winapi/character_code_conversion.hpp>
|
||||
#include <boost/winapi/local_memory.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# endif
|
||||
|
||||
_snprintf( buffer, len - 1, "Unknown error (%d)", ev );
|
||||
|
||||
buffer[ len - 1 ] = 0;
|
||||
return buffer;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
|
||||
{
|
||||
std::snprintf( buffer, len, "Unknown error (%d)", ev );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline boost::winapi::UINT_ message_cp_win32()
|
||||
{
|
||||
#if defined(BOOST_SYSTEM_USE_UTF8)
|
||||
|
||||
return boost::winapi::CP_UTF8_;
|
||||
|
||||
#else
|
||||
|
||||
return boost::winapi::CP_ACP_;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
boost::winapi::UINT_ const code_page = message_cp_win32();
|
||||
|
||||
int r = 0;
|
||||
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
|
||||
if( code_page == boost::winapi::CP_ACP_ )
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
buffer,
|
||||
static_cast<DWORD_>( len ),
|
||||
NULL
|
||||
);
|
||||
|
||||
r = static_cast<int>( retval );
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
wchar_t * lpMsgBuf = 0;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
if( retval != 0 )
|
||||
{
|
||||
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, buffer, static_cast<int>( len ), NULL, NULL );
|
||||
boost::winapi::LocalFree( lpMsgBuf );
|
||||
if ( r != 0 ) --r; // exclude null terminator
|
||||
}
|
||||
}
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
|
||||
{
|
||||
buffer[ --r ] = 0;
|
||||
}
|
||||
|
||||
if( r > 0 && buffer[ r-1 ] == '.' )
|
||||
{
|
||||
buffer[ --r ] = 0;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
struct local_free
|
||||
{
|
||||
void * p_;
|
||||
|
||||
~local_free()
|
||||
{
|
||||
boost::winapi::LocalFree( p_ );
|
||||
}
|
||||
};
|
||||
|
||||
inline std::string unknown_message_win32( int ev )
|
||||
{
|
||||
char buffer[ 38 ];
|
||||
return unknown_message_win32( ev, buffer, sizeof( buffer ) );
|
||||
}
|
||||
|
||||
inline std::string system_category_message_win32( int ev )
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
wchar_t * lpMsgBuf = 0;
|
||||
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
(LPWSTR_) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
if( retval == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
local_free lf_ = { lpMsgBuf };
|
||||
(void)lf_;
|
||||
|
||||
UINT_ const code_page = message_cp_win32();
|
||||
|
||||
int r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, 0, 0, NULL, NULL );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
std::string buffer( r, char() );
|
||||
|
||||
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return unknown_message_win32( ev );
|
||||
}
|
||||
|
||||
--r; // exclude null terminator
|
||||
|
||||
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
if( r > 0 && buffer[ r-1 ] == '.' )
|
||||
{
|
||||
--r;
|
||||
}
|
||||
|
||||
buffer.resize( r );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline error_condition system_category_default_error_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
{
|
||||
// When using the Windows Runtime, most system errors are reported as HRESULTs.
|
||||
// We want to map the common Win32 errors to their equivalent error condition,
|
||||
// whether or not they are reported via an HRESULT.
|
||||
|
||||
#define BOOST_SYSTEM_FAILED(hr) ((hr) < 0)
|
||||
#define BOOST_SYSTEM_HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
|
||||
#define BOOST_SYSTEM_HRESULT_CODE(hr) ((hr) & 0xFFFF)
|
||||
#define BOOST_SYSTEM_FACILITY_WIN32 7
|
||||
|
||||
if( BOOST_SYSTEM_FAILED( ev ) && BOOST_SYSTEM_HRESULT_FACILITY( ev ) == BOOST_SYSTEM_FACILITY_WIN32 )
|
||||
{
|
||||
ev = BOOST_SYSTEM_HRESULT_CODE( ev );
|
||||
}
|
||||
|
||||
#undef BOOST_SYSTEM_FAILED
|
||||
#undef BOOST_SYSTEM_HRESULT_FACILITY
|
||||
#undef BOOST_SYSTEM_HRESULT_CODE
|
||||
#undef BOOST_SYSTEM_FACILITY_WIN32
|
||||
|
||||
using namespace boost::winapi;
|
||||
using namespace errc;
|
||||
|
||||
// Windows system -> posix_errno decode table
|
||||
// see WinError.h comments for descriptions of errors
|
||||
|
||||
switch ( ev )
|
||||
{
|
||||
case 0: return make_error_condition( success );
|
||||
|
||||
case ERROR_ACCESS_DENIED_: return make_error_condition( permission_denied );
|
||||
case ERROR_ALREADY_EXISTS_: return make_error_condition( file_exists );
|
||||
case ERROR_BAD_UNIT_: return make_error_condition( no_such_device );
|
||||
case ERROR_BUFFER_OVERFLOW_: return make_error_condition( filename_too_long );
|
||||
case ERROR_BUSY_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_BUSY_DRIVE_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_CANNOT_MAKE_: return make_error_condition( permission_denied );
|
||||
case ERROR_CANTOPEN_: return make_error_condition( io_error );
|
||||
case ERROR_CANTREAD_: return make_error_condition( io_error );
|
||||
case ERROR_CANTWRITE_: return make_error_condition( io_error );
|
||||
case ERROR_CONNECTION_ABORTED_: return make_error_condition( connection_aborted );
|
||||
case ERROR_CURRENT_DIRECTORY_: return make_error_condition( permission_denied );
|
||||
case ERROR_DEV_NOT_EXIST_: return make_error_condition( no_such_device );
|
||||
case ERROR_DEVICE_IN_USE_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_DIR_NOT_EMPTY_: return make_error_condition( directory_not_empty );
|
||||
case ERROR_DIRECTORY_: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid"
|
||||
case ERROR_DISK_FULL_: return make_error_condition( no_space_on_device );
|
||||
case ERROR_FILE_EXISTS_: return make_error_condition( file_exists );
|
||||
case ERROR_FILE_NOT_FOUND_: return make_error_condition( no_such_file_or_directory );
|
||||
case ERROR_HANDLE_DISK_FULL_: return make_error_condition( no_space_on_device );
|
||||
case ERROR_INVALID_ACCESS_: return make_error_condition( permission_denied );
|
||||
case ERROR_INVALID_DRIVE_: return make_error_condition( no_such_device );
|
||||
case ERROR_INVALID_FUNCTION_: return make_error_condition( function_not_supported );
|
||||
case ERROR_INVALID_HANDLE_: return make_error_condition( invalid_argument );
|
||||
case ERROR_INVALID_NAME_: return make_error_condition( invalid_argument );
|
||||
case ERROR_LOCK_VIOLATION_: return make_error_condition( no_lock_available );
|
||||
case ERROR_LOCKED_: return make_error_condition( no_lock_available );
|
||||
case ERROR_NEGATIVE_SEEK_: return make_error_condition( invalid_argument );
|
||||
case ERROR_NOACCESS_: return make_error_condition( permission_denied );
|
||||
case ERROR_NOT_ENOUGH_MEMORY_: return make_error_condition( not_enough_memory );
|
||||
case ERROR_NOT_READY_: return make_error_condition( resource_unavailable_try_again );
|
||||
case ERROR_NOT_SAME_DEVICE_: return make_error_condition( cross_device_link );
|
||||
case ERROR_OPEN_FAILED_: return make_error_condition( io_error );
|
||||
case ERROR_OPEN_FILES_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_OPERATION_ABORTED_: return make_error_condition( operation_canceled );
|
||||
case ERROR_OUTOFMEMORY_: return make_error_condition( not_enough_memory );
|
||||
case ERROR_PATH_NOT_FOUND_: return make_error_condition( no_such_file_or_directory );
|
||||
case ERROR_READ_FAULT_: return make_error_condition( io_error );
|
||||
case ERROR_RETRY_: return make_error_condition( resource_unavailable_try_again );
|
||||
case ERROR_SEEK_: return make_error_condition( io_error );
|
||||
case ERROR_SHARING_VIOLATION_: return make_error_condition( permission_denied );
|
||||
case ERROR_TOO_MANY_OPEN_FILES_: return make_error_condition( too_many_files_open );
|
||||
case ERROR_WRITE_FAULT_: return make_error_condition( io_error );
|
||||
case ERROR_WRITE_PROTECT_: return make_error_condition( permission_denied );
|
||||
case WSAEACCES_: return make_error_condition( permission_denied );
|
||||
case WSAEADDRINUSE_: return make_error_condition( address_in_use );
|
||||
case WSAEADDRNOTAVAIL_: return make_error_condition( address_not_available );
|
||||
case WSAEAFNOSUPPORT_: return make_error_condition( address_family_not_supported );
|
||||
case WSAEALREADY_: return make_error_condition( connection_already_in_progress );
|
||||
case WSAEBADF_: return make_error_condition( bad_file_descriptor );
|
||||
case WSAECONNABORTED_: return make_error_condition( connection_aborted );
|
||||
case WSAECONNREFUSED_: return make_error_condition( connection_refused );
|
||||
case WSAECONNRESET_: return make_error_condition( connection_reset );
|
||||
case WSAEDESTADDRREQ_: return make_error_condition( destination_address_required );
|
||||
case WSAEFAULT_: return make_error_condition( bad_address );
|
||||
case WSAEHOSTUNREACH_: return make_error_condition( host_unreachable );
|
||||
case WSAEINPROGRESS_: return make_error_condition( operation_in_progress );
|
||||
case WSAEINTR_: return make_error_condition( interrupted );
|
||||
case WSAEINVAL_: return make_error_condition( invalid_argument );
|
||||
case WSAEISCONN_: return make_error_condition( already_connected );
|
||||
case WSAEMFILE_: return make_error_condition( too_many_files_open );
|
||||
case WSAEMSGSIZE_: return make_error_condition( message_size );
|
||||
case WSAENAMETOOLONG_: return make_error_condition( filename_too_long );
|
||||
case WSAENETDOWN_: return make_error_condition( network_down );
|
||||
case WSAENETRESET_: return make_error_condition( network_reset );
|
||||
case WSAENETUNREACH_: return make_error_condition( network_unreachable );
|
||||
case WSAENOBUFS_: return make_error_condition( no_buffer_space );
|
||||
case WSAENOPROTOOPT_: return make_error_condition( no_protocol_option );
|
||||
case WSAENOTCONN_: return make_error_condition( not_connected );
|
||||
case WSAENOTSOCK_: return make_error_condition( not_a_socket );
|
||||
case WSAEOPNOTSUPP_: return make_error_condition( operation_not_supported );
|
||||
case WSAEPROTONOSUPPORT_: return make_error_condition( protocol_not_supported );
|
||||
case WSAEPROTOTYPE_: return make_error_condition( wrong_protocol_type );
|
||||
case WSAETIMEDOUT_: return make_error_condition( timed_out );
|
||||
case WSAEWOULDBLOCK_: return make_error_condition( operation_would_block );
|
||||
|
||||
default: return error_condition( ev, system_category() );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
59
include/boost/system/detail/throws.hpp
Normal file
59
include/boost/system/detail/throws.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_code;
|
||||
|
||||
} // namespace system
|
||||
|
||||
// boost::throws()
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Misuse of the error_code object is turned into a noisy failure by
|
||||
// poisoning the reference. This particular implementation doesn't
|
||||
// produce warnings or errors from popular compilers, is very efficient
|
||||
// (as determined by inspecting generated code), and does not suffer
|
||||
// from order of initialization problems. In practice, it also seems
|
||||
// cause user function error handling implementation errors to be detected
|
||||
// very early in the development cycle.
|
||||
|
||||
inline system::error_code* throws()
|
||||
{
|
||||
// See github.com/boostorg/system/pull/12 by visigoth for why the return
|
||||
// is poisoned with nonzero rather than (0). A test, test_throws_usage(),
|
||||
// has been added to error_code_test.cpp, and as visigoth mentioned it
|
||||
// fails on clang for release builds with a return of 0 but works fine
|
||||
// with (1).
|
||||
// Since the undefined behavior sanitizer (-fsanitize=undefined) does not
|
||||
// allow a reference to be formed to the unaligned address of (1), we use
|
||||
// (8) instead.
|
||||
|
||||
return reinterpret_cast<system::error_code*>(8);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline system::error_code& throws()
|
||||
{
|
||||
return *detail::throws();
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_TO_STD_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_TO_STD_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Support for interoperability between Boost.System and <system_error>
|
||||
//
|
||||
// Copyright 2018 Peter Dimov
|
||||
@@ -7,6 +10,10 @@
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <system_error>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -80,12 +87,12 @@ struct cat_ptr_less
|
||||
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
|
||||
{
|
||||
if( cat == boost::system::system_category() )
|
||||
if( cat.id_ == boost::system::detail::system_category_id )
|
||||
{
|
||||
static const std_category system_instance( &cat, 0x1F4D7 );
|
||||
return system_instance;
|
||||
}
|
||||
else if( cat == boost::system::generic_category() )
|
||||
else if( cat.id_ == boost::system::detail::generic_category_id )
|
||||
{
|
||||
static const std_category generic_instance( &cat, 0x1F4D3 );
|
||||
return generic_instance;
|
||||
@@ -180,3 +187,5 @@ inline bool std_category::equivalent( const std::error_code & code, int conditio
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_TO_STD_CATEGORY_HPP_INCLUDED
|
||||
50
include/boost/system/errc.hpp
Normal file
50
include/boost/system/errc.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef BOOST_SYSTEM_ERRC_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_ERRC_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018, 2020
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// make_* functions for errc::errc_t
|
||||
|
||||
namespace errc
|
||||
{
|
||||
|
||||
// explicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_code( e, generic_category() );
|
||||
}
|
||||
|
||||
// implicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( e, generic_category() );
|
||||
}
|
||||
|
||||
} // namespace errc
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_ERRC_HPP_INCLUDED
|
||||
13
include/boost/system/error_category.hpp
Normal file
13
include/boost/system/error_category.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED
|
||||
@@ -10,25 +10,14 @@
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/api_config.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/system/detail/throws.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
// TODO: undef these macros if not already defined
|
||||
#include <boost/cerrno.hpp>
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
# include <system_error>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
|
||||
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -36,722 +25,8 @@ namespace boost
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_code; // values defined by the operating system
|
||||
class error_condition; // portable generic values defined below, but ultimately
|
||||
// based on the POSIX standard
|
||||
|
||||
// "Concept" helpers
|
||||
|
||||
template<class T> struct is_error_code_enum
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template<class T> struct is_error_condition_enum
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
// Generic error_conditions
|
||||
|
||||
namespace errc
|
||||
{
|
||||
|
||||
enum errc_t
|
||||
{
|
||||
success = 0,
|
||||
address_family_not_supported = EAFNOSUPPORT,
|
||||
address_in_use = EADDRINUSE,
|
||||
address_not_available = EADDRNOTAVAIL,
|
||||
already_connected = EISCONN,
|
||||
argument_list_too_long = E2BIG,
|
||||
argument_out_of_domain = EDOM,
|
||||
bad_address = EFAULT,
|
||||
bad_file_descriptor = EBADF,
|
||||
bad_message = EBADMSG,
|
||||
broken_pipe = EPIPE,
|
||||
connection_aborted = ECONNABORTED,
|
||||
connection_already_in_progress = EALREADY,
|
||||
connection_refused = ECONNREFUSED,
|
||||
connection_reset = ECONNRESET,
|
||||
cross_device_link = EXDEV,
|
||||
destination_address_required = EDESTADDRREQ,
|
||||
device_or_resource_busy = EBUSY,
|
||||
directory_not_empty = ENOTEMPTY,
|
||||
executable_format_error = ENOEXEC,
|
||||
file_exists = EEXIST,
|
||||
file_too_large = EFBIG,
|
||||
filename_too_long = ENAMETOOLONG,
|
||||
function_not_supported = ENOSYS,
|
||||
host_unreachable = EHOSTUNREACH,
|
||||
identifier_removed = EIDRM,
|
||||
illegal_byte_sequence = EILSEQ,
|
||||
inappropriate_io_control_operation = ENOTTY,
|
||||
interrupted = EINTR,
|
||||
invalid_argument = EINVAL,
|
||||
invalid_seek = ESPIPE,
|
||||
io_error = EIO,
|
||||
is_a_directory = EISDIR,
|
||||
message_size = EMSGSIZE,
|
||||
network_down = ENETDOWN,
|
||||
network_reset = ENETRESET,
|
||||
network_unreachable = ENETUNREACH,
|
||||
no_buffer_space = ENOBUFS,
|
||||
no_child_process = ECHILD,
|
||||
no_link = ENOLINK,
|
||||
no_lock_available = ENOLCK,
|
||||
no_message_available = ENODATA,
|
||||
no_message = ENOMSG,
|
||||
no_protocol_option = ENOPROTOOPT,
|
||||
no_space_on_device = ENOSPC,
|
||||
no_stream_resources = ENOSR,
|
||||
no_such_device_or_address = ENXIO,
|
||||
no_such_device = ENODEV,
|
||||
no_such_file_or_directory = ENOENT,
|
||||
no_such_process = ESRCH,
|
||||
not_a_directory = ENOTDIR,
|
||||
not_a_socket = ENOTSOCK,
|
||||
not_a_stream = ENOSTR,
|
||||
not_connected = ENOTCONN,
|
||||
not_enough_memory = ENOMEM,
|
||||
not_supported = ENOTSUP,
|
||||
operation_canceled = ECANCELED,
|
||||
operation_in_progress = EINPROGRESS,
|
||||
operation_not_permitted = EPERM,
|
||||
operation_not_supported = EOPNOTSUPP,
|
||||
operation_would_block = EWOULDBLOCK,
|
||||
owner_dead = EOWNERDEAD,
|
||||
permission_denied = EACCES,
|
||||
protocol_error = EPROTO,
|
||||
protocol_not_supported = EPROTONOSUPPORT,
|
||||
read_only_file_system = EROFS,
|
||||
resource_deadlock_would_occur = EDEADLK,
|
||||
resource_unavailable_try_again = EAGAIN,
|
||||
result_out_of_range = ERANGE,
|
||||
state_not_recoverable = ENOTRECOVERABLE,
|
||||
stream_timeout = ETIME,
|
||||
text_file_busy = ETXTBSY,
|
||||
timed_out = ETIMEDOUT,
|
||||
too_many_files_open_in_system = ENFILE,
|
||||
too_many_files_open = EMFILE,
|
||||
too_many_links = EMLINK,
|
||||
too_many_symbolic_link_levels = ELOOP,
|
||||
value_too_large = EOVERFLOW,
|
||||
wrong_protocol_type = EPROTOTYPE
|
||||
};
|
||||
|
||||
} // namespace errc
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
namespace posix = errc;
|
||||
namespace posix_error = errc;
|
||||
|
||||
#endif
|
||||
|
||||
template<> struct is_error_condition_enum<errc::errc_t>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
// class error_category
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push )
|
||||
// 'this' : used in base member initializer list
|
||||
#pragma warning( disable: 4355 )
|
||||
#endif
|
||||
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE error_category
|
||||
{
|
||||
private:
|
||||
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
|
||||
error_category( error_category const & ) = delete;
|
||||
error_category& operator=( error_category const & ) = delete;
|
||||
|
||||
#else
|
||||
private:
|
||||
|
||||
error_category( error_category const & );
|
||||
error_category& operator=( error_category const & );
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
boost::ulong_long_type id_;
|
||||
|
||||
protected:
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
|
||||
|
||||
~error_category() = default;
|
||||
|
||||
#else
|
||||
|
||||
// We'd like to make the destructor protected, to make code that deletes
|
||||
// an error_category* not compile; unfortunately, doing the below makes
|
||||
// the destructor user-provided and hence breaks use after main, as the
|
||||
// categories may get destroyed before code that uses them
|
||||
|
||||
// ~error_category() {}
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id )
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT = 0;
|
||||
|
||||
virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual std::string message( int ev ) const = 0;
|
||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual bool failed( int ev ) const BOOST_NOEXCEPT;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return rhs.id_ == 0? this == &rhs: id_ == rhs.id_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!=( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator<( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( id_ < rhs.id_ )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( id_ > rhs.id_ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( rhs.id_ != 0 )
|
||||
{
|
||||
return false; // equal
|
||||
}
|
||||
|
||||
return std::less<error_category const *>()( this, &rhs );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_category const & () const;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
// predefined error categories
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
// clang++ 3.8 and below: initialization of const object
|
||||
// requires a user-provided default constructor
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
|
||||
error_category( ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
return "generic";
|
||||
}
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
|
||||
error_category( ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B )
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
|
||||
{
|
||||
return "system";
|
||||
}
|
||||
|
||||
error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
|
||||
std::string message( int ev ) const BOOST_OVERRIDE;
|
||||
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// generic_category(), system_category()
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct BOOST_SYMBOL_VISIBLE cat_holder
|
||||
{
|
||||
static constexpr system_error_category system_category_instance{};
|
||||
static constexpr generic_error_category generic_category_instance{};
|
||||
};
|
||||
|
||||
// Before C++17 it was mandatory to redeclare all static constexpr
|
||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||
template<class T> constexpr system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> constexpr generic_error_category cat_holder<T>::generic_category_instance;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::system_category_instance;
|
||||
}
|
||||
|
||||
constexpr error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::generic_category_instance;
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#if !defined(__SUNPRO_CC) // trailing __global is not supported
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
|
||||
#endif
|
||||
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category system_category_instance;
|
||||
return system_category_instance;
|
||||
}
|
||||
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category generic_category_instance;
|
||||
return generic_category_instance;
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
// deprecated synonyms
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
inline const error_category & get_system_category() { return system_category(); }
|
||||
inline const error_category & get_generic_category() { return generic_category(); }
|
||||
inline const error_category & get_posix_category() { return generic_category(); }
|
||||
static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category();
|
||||
static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category();
|
||||
static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category();
|
||||
|
||||
#endif
|
||||
|
||||
// enable_if
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<bool C, class T = void> struct enable_if
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T> struct enable_if<false, T>
|
||||
{
|
||||
};
|
||||
|
||||
// failed_impl
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
if( cat == system_category() || cat == generic_category() )
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// class error_condition
|
||||
|
||||
// error_conditions are portable, error_codes are system or library specific
|
||||
|
||||
class error_condition
|
||||
{
|
||||
private:
|
||||
|
||||
int val_;
|
||||
bool failed_;
|
||||
error_category const * cat_;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT:
|
||||
val_( 0 ), failed_( false ), cat_( &generic_category() )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
|
||||
typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( e );
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = val;
|
||||
failed_ = detail::failed_impl( val, cat );
|
||||
cat_ = &cat;
|
||||
}
|
||||
|
||||
template<typename ErrorConditionEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
|
||||
operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = 0;
|
||||
failed_ = false;
|
||||
cat_ = &generic_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *cat_;
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
}
|
||||
|
||||
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return !failed_;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_condition () const
|
||||
{
|
||||
return std::error_condition( value(), category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
// class error_code
|
||||
|
||||
// We want error_code to be a value type that can be copied without slicing
|
||||
// and without requiring heap allocation, but we also want it to have
|
||||
// polymorphic behavior based on the error category. This is achieved by
|
||||
// abstract base class error_category supplying the polymorphic behavior,
|
||||
// and error_code containing a pointer to an object of a type derived
|
||||
// from error_category.
|
||||
|
||||
class error_code
|
||||
{
|
||||
private:
|
||||
|
||||
int val_;
|
||||
bool failed_;
|
||||
const error_category * cat_;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
|
||||
val_( 0 ), failed_( false ), cat_( &system_category() )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
|
||||
val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
|
||||
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( e );
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = val;
|
||||
failed_ = detail::failed_impl( val, cat );
|
||||
cat_ = &cat;
|
||||
}
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
|
||||
operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
val_ = 0;
|
||||
failed_ = false;
|
||||
cat_ = &system_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
|
||||
{
|
||||
return *cat_;
|
||||
}
|
||||
|
||||
error_condition default_error_condition() const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->default_error_condition( value() );
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
{
|
||||
return cat_->message( value() );
|
||||
}
|
||||
|
||||
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return cat_->message( value(), buffer, len );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return failed_? unspecified_bool_true: 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
{
|
||||
return !failed_;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_code () const
|
||||
{
|
||||
return std::error_code( value(), category() );
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
// boost::throws()
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Misuse of the error_code object is turned into a noisy failure by
|
||||
// poisoning the reference. This particular implementation doesn't
|
||||
// produce warnings or errors from popular compilers, is very efficient
|
||||
// (as determined by inspecting generated code), and does not suffer
|
||||
// from order of initialization problems. In practice, it also seems
|
||||
// cause user function error handling implementation errors to be detected
|
||||
// very early in the development cycle.
|
||||
|
||||
inline system::error_code* throws()
|
||||
{
|
||||
// See github.com/boostorg/system/pull/12 by visigoth for why the return
|
||||
// is poisoned with nonzero rather than (0). A test, test_throws_usage(),
|
||||
// has been added to error_code_test.cpp, and as visigoth mentioned it
|
||||
// fails on clang for release builds with a return of 0 but works fine
|
||||
// with (1).
|
||||
// Since the undefined behavior sanitizer (-fsanitize=undefined) does not
|
||||
// allow a reference to be formed to the unaligned address of (1), we use
|
||||
// (8) instead.
|
||||
|
||||
return reinterpret_cast<system::error_code*>(8);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline system::error_code& throws()
|
||||
{
|
||||
return *detail::throws();
|
||||
}
|
||||
|
||||
// non-member functions of error_code and error_condition
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
|
||||
{
|
||||
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
|
||||
@@ -772,201 +47,8 @@ inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BO
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
|
||||
template <class charT, class traits>
|
||||
inline std::basic_ostream<charT,traits>&
|
||||
operator<< (std::basic_ostream<charT,traits>& os, error_code ec)
|
||||
{
|
||||
os << ec.category().name() << ':' << ec.value();
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::size_t hash_value( error_code const & ec )
|
||||
{
|
||||
error_category const & cat = ec.category();
|
||||
|
||||
boost::ulong_long_type id_ = cat.id_;
|
||||
|
||||
if( id_ == 0 )
|
||||
{
|
||||
id_ = reinterpret_cast<boost::uintptr_t>( &cat );
|
||||
}
|
||||
|
||||
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
|
||||
boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
|
||||
|
||||
// id
|
||||
|
||||
hv ^= id_;
|
||||
hv *= prime;
|
||||
|
||||
// value
|
||||
|
||||
hv ^= static_cast<unsigned>( ec.value() );
|
||||
hv *= prime;
|
||||
|
||||
return static_cast<std::size_t>( hv );
|
||||
}
|
||||
|
||||
// make_* functions for errc::errc_t
|
||||
|
||||
namespace errc
|
||||
{
|
||||
|
||||
// explicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_code( e, generic_category() );
|
||||
}
|
||||
|
||||
// implicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( e, generic_category() );
|
||||
}
|
||||
|
||||
} // namespace errc
|
||||
|
||||
// error_category default implementation
|
||||
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::string m = this->message( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
std::strncpy( buffer, m.c_str(), len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
return "Message text unavailable";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool error_category::failed( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// generic_error_category implementation
|
||||
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
|
||||
inline std::string boost::system::detail::generic_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
// system_error_category implementation
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/system_category_win32.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_default_error_condition_win32( ev );
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return system_category_message_win32( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_message_win32( ev, buffer, len );
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
#include <boost/system/detail/system_category_posix.hpp>
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_default_error_condition_posix( ev );
|
||||
}
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return generic_error_category_message( ev, buffer, len );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_WINDOWS_API)
|
||||
|
||||
// interoperability with std::error_code, std::error_condition
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#include <boost/system/detail/std_interoperability.hpp>
|
||||
|
||||
inline boost::system::error_category::operator std::error_category const & () const
|
||||
{
|
||||
return boost::system::detail::to_std_category( *this );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
|
||||
|
||||
13
include/boost/system/error_condition.hpp
Normal file
13
include/boost/system/error_condition.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED
|
||||
13
include/boost/system/generic_category.hpp
Normal file
13
include/boost/system/generic_category.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED
|
||||
30
include/boost/system/is_error_code_enum.hpp
Normal file
30
include/boost/system/is_error_code_enum.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_code;
|
||||
|
||||
template<class T> struct is_error_code_enum
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED
|
||||
30
include/boost/system/is_error_condition_enum.hpp
Normal file
30
include/boost/system/is_error_condition_enum.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_condition;
|
||||
|
||||
template<class T> struct is_error_condition_enum
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED
|
||||
14
include/boost/system/system_category.hpp
Normal file
14
include/boost/system/system_category.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/system_category.hpp>
|
||||
#include <boost/system/detail/system_category_impl.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED
|
||||
@@ -73,3 +73,15 @@ lib std_single_instance_lib2 : std_single_instance_2.cpp : <link>shared:<define>
|
||||
system-run std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp ;
|
||||
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>static : std_single_instance_lib_static ;
|
||||
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared <define>STD_SINGLE_INSTANCE_SHARED : std_single_instance_lib_shared ;
|
||||
|
||||
run is_error_code_enum_test.cpp ;
|
||||
run is_error_condition_enum_test.cpp ;
|
||||
run errc_test.cpp ;
|
||||
run errc_test2.cpp ;
|
||||
run error_category_test2.cpp ;
|
||||
run error_condition_test.cpp ;
|
||||
run error_condition_test2.cpp ;
|
||||
run generic_category_test2.cpp ;
|
||||
run generic_category_test3.cpp ;
|
||||
run system_category_test2.cpp ;
|
||||
run system_category_test3.cpp ;
|
||||
|
||||
18
test/errc_test.cpp
Normal file
18
test/errc_test.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/system/is_error_condition_enum.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::success ), 0 );
|
||||
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::no_such_file_or_directory ), ENOENT );
|
||||
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::address_family_not_supported ), EAFNOSUPPORT );
|
||||
|
||||
BOOST_TEST( boost::system::is_error_condition_enum< boost::system::errc::errc_t >::value );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
20
test/errc_test2.cpp
Normal file
20
test/errc_test2.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_EQ( make_error_code( boost::system::errc::success ).value(), 0 );
|
||||
BOOST_TEST_EQ( make_error_condition( boost::system::errc::success ).value(), 0 );
|
||||
|
||||
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
|
||||
BOOST_TEST_EQ( make_error_condition( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
|
||||
|
||||
BOOST_TEST_EQ( make_error_code( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
|
||||
BOOST_TEST_EQ( make_error_condition( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
79
test/error_category_test2.cpp
Normal file
79
test/error_category_test2.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
// Copyright 2018, 2020 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
// Avoid spurious VC++ warnings
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
//
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
class user_category: public sys::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return "user";
|
||||
}
|
||||
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
std::sprintf( buffer, "user message %d", ev );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
using sys::error_category::message;
|
||||
};
|
||||
|
||||
static user_category s_cat_1;
|
||||
static user_category s_cat_2;
|
||||
|
||||
int main()
|
||||
{
|
||||
// default_error_condition
|
||||
|
||||
BOOST_TEST( s_cat_1.default_error_condition( 1 ).value() == 1 );
|
||||
BOOST_TEST( s_cat_1.default_error_condition( 1 ).category() == s_cat_1 );
|
||||
|
||||
BOOST_TEST( s_cat_2.default_error_condition( 2 ).value() == 2 );
|
||||
BOOST_TEST( s_cat_2.default_error_condition( 2 ).category() == s_cat_2 );
|
||||
|
||||
// equivalent
|
||||
|
||||
BOOST_TEST( s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 1 ) ) );
|
||||
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 2 ) ) );
|
||||
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_2.default_error_condition( 2 ) ) );
|
||||
|
||||
// message
|
||||
|
||||
{
|
||||
char buffer[ 256 ];
|
||||
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), s_cat_1.message( 1 ).c_str() );
|
||||
}
|
||||
|
||||
{
|
||||
char buffer[ 4 ];
|
||||
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), "use" );
|
||||
}
|
||||
|
||||
// ==
|
||||
|
||||
BOOST_TEST_NOT( s_cat_1 == s_cat_2 );
|
||||
BOOST_TEST( s_cat_1 != s_cat_2 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
31
test/error_condition_test.cpp
Normal file
31
test/error_condition_test.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_condition en;
|
||||
|
||||
BOOST_TEST_EQ( en.value(), 0 );
|
||||
BOOST_TEST( !en );
|
||||
|
||||
sys::error_condition en2( en );
|
||||
|
||||
BOOST_TEST( en == en2 );
|
||||
BOOST_TEST_NOT( en != en2 );
|
||||
|
||||
en2.assign( 1, en.category() );
|
||||
|
||||
BOOST_TEST_EQ( en2.value(), 1 );
|
||||
BOOST_TEST( en2 );
|
||||
|
||||
BOOST_TEST_NOT( en == en2 );
|
||||
BOOST_TEST( en != en2 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
25
test/error_condition_test2.cpp
Normal file
25
test/error_condition_test2.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/system/errc.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_condition en( sys::errc::no_such_file_or_directory );
|
||||
|
||||
BOOST_TEST_EQ( en.value(), ENOENT );
|
||||
|
||||
BOOST_TEST( en );
|
||||
BOOST_TEST( !!en );
|
||||
|
||||
BOOST_TEST( en == make_error_condition( sys::errc::no_such_file_or_directory ) );
|
||||
|
||||
BOOST_TEST( en.category() == sys::error_condition().category() );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
20
test/generic_category_test2.cpp
Normal file
20
test/generic_category_test2.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
// Tests whether generic_category() is functional when only
|
||||
// generic_category.hpp is included
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_category const & cat = sys::generic_category();
|
||||
|
||||
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
30
test/generic_category_test3.cpp
Normal file
30
test/generic_category_test3.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cerrno>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_category const & cat = sys::generic_category();
|
||||
|
||||
// name
|
||||
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
|
||||
|
||||
// default_error_condition
|
||||
BOOST_TEST( cat.default_error_condition( 0 ) == sys::error_condition( 0, cat ) );
|
||||
BOOST_TEST( cat.default_error_condition( ENOENT ) == sys::error_condition( ENOENT, cat ) );
|
||||
BOOST_TEST( cat.default_error_condition( -1 ) == sys::error_condition( -1, cat ) );
|
||||
|
||||
// failed
|
||||
BOOST_TEST( !cat.failed( 0 ) );
|
||||
BOOST_TEST( cat.failed( ENOENT ) );
|
||||
BOOST_TEST( cat.failed( -1 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
41
test/is_error_code_enum_test.cpp
Normal file
41
test/is_error_code_enum_test.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/is_error_code_enum.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
enum error
|
||||
{
|
||||
success = 0,
|
||||
e1,
|
||||
e2,
|
||||
e3
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
template<> struct is_error_code_enum< ::error >
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
boost::system::error_code make_error_code( ::error e );
|
||||
|
||||
enum not_error
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( boost::system::is_error_code_enum< ::error >::value );
|
||||
BOOST_TEST( !boost::system::is_error_code_enum< ::not_error >::value );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
40
test/is_error_condition_enum_test.cpp
Normal file
40
test/is_error_condition_enum_test.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/is_error_condition_enum.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
enum condition
|
||||
{
|
||||
c1 = 1,
|
||||
c2,
|
||||
c3
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
template<> struct is_error_condition_enum< ::condition >
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
boost::system::error_condition make_error_condition( ::condition e );
|
||||
|
||||
enum not_condition
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( boost::system::is_error_condition_enum< ::condition >::value );
|
||||
BOOST_TEST( !boost::system::is_error_condition_enum< ::not_condition >::value );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
20
test/system_category_test2.cpp
Normal file
20
test/system_category_test2.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
// Tests whether system_category() is functional when only
|
||||
// system_category.hpp is included
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_category const & cat = sys::system_category();
|
||||
|
||||
BOOST_TEST_CSTR_EQ( cat.name(), "system" );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
39
test/system_category_test3.cpp
Normal file
39
test/system_category_test3.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/system/system_category.hpp>
|
||||
#include <boost/system/generic_category.hpp>
|
||||
#include <boost/system/error_condition.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace sys = boost::system;
|
||||
|
||||
int main()
|
||||
{
|
||||
sys::error_category const & cat = sys::system_category();
|
||||
|
||||
// name
|
||||
BOOST_TEST_CSTR_EQ( cat.name(), "system" );
|
||||
|
||||
// default_error_condition
|
||||
BOOST_TEST( cat.default_error_condition( 0 ) == sys::error_condition() );
|
||||
BOOST_TEST( cat.default_error_condition( -1 ) == sys::error_condition( -1, cat ) );
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
||||
BOOST_TEST( cat.default_error_condition( 5 ) == sys::error_condition( EACCES, sys::generic_category() ) );
|
||||
|
||||
#else
|
||||
|
||||
BOOST_TEST( cat.default_error_condition( EACCES ) == sys::error_condition( EACCES, sys::generic_category() ) );
|
||||
|
||||
#endif
|
||||
|
||||
// failed
|
||||
BOOST_TEST( !cat.failed( 0 ) );
|
||||
BOOST_TEST( cat.failed( 5 ) );
|
||||
BOOST_TEST( cat.failed( -1 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user