1//
2// impl/error_code.ipp
3// ~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#ifndef ASIO_IMPL_ERROR_CODE_IPP
12#define ASIO_IMPL_ERROR_CODE_IPP
13
14
15#include "asio/detail/config.hpp"
16# include <cerrno>
17# include <cstring>
18# include <string>
19#include "asio/detail/local_free_on_block_exit.hpp"
20#include "asio/detail/socket_types.hpp"
21#include "asio/error_code.hpp"
22
23#include "asio/detail/push_options.hpp"
24
25namespace asio {
26namespace detail {
27
28class system_category : public error_category
29{
30public:
31  const char* name() const ASIO_ERROR_CATEGORY_NOEXCEPT
32  {
33    return "asio.system";
34  }
35
36  std::string message(int value) const
37  {
38#if !defined(__sun)
39    if (value == ECANCELED)
40      return "Operation aborted.";
41#endif // !defined(__sun)
42#if defined(__sun) || defined(__QNX__) || defined(__SYMBIAN32__)
43    using namespace std;
44    return strerror(value);
45#elif defined(__MACH__) && defined(__APPLE__)    || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)    || defined(_AIX) || defined(__hpux) || defined(__osf__)    || defined(__ANDROID__)
46    char buf[256] = "";
47    using namespace std;
48    strerror_r(value, buf, sizeof(buf));
49    return buf;
50#else
51    char buf[256] = "";
52    return strerror_r(value, buf, sizeof(buf));
53#endif
54  }
55};
56
57} // namespace detail
58
59const error_category& system_category()
60{
61  static detail::system_category instance;
62  return instance;
63}
64
65} // namespace asio
66
67#include "asio/detail/pop_options.hpp"
68
69#endif // ASIO_IMPL_ERROR_CODE_IPP
70