tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / libc++ / dist / libcxx / src / system_error.cpp
blobb40409f854ab9df85052c5e664594e0d9b53a7da
1 //===---------------------- system_error.cpp ------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #define _LIBCPP_BUILDING_SYSTEM_ERROR
11 #include "system_error"
12 #include "string"
13 #include "cstring"
15 _LIBCPP_BEGIN_NAMESPACE_STD
17 // class error_category
19 error_category::error_category() _NOEXCEPT
23 error_category::~error_category() _NOEXCEPT
27 error_condition
28 error_category::default_error_condition(int ev) const _NOEXCEPT
30 return error_condition(ev, *this);
33 bool
34 error_category::equivalent(int code, const error_condition& condition) const _NOEXCEPT
36 return default_error_condition(code) == condition;
39 bool
40 error_category::equivalent(const error_code& code, int condition) const _NOEXCEPT
42 return *this == code.category() && code.value() == condition;
45 string
46 __do_message::message(int ev) const
48 return string(strerror(ev));
51 class _LIBCPP_HIDDEN __generic_error_category
52 : public __do_message
54 public:
55 virtual const char* name() const _NOEXCEPT;
56 virtual string message(int ev) const;
59 const char*
60 __generic_error_category::name() const _NOEXCEPT
62 return "generic";
65 string
66 __generic_error_category::message(int ev) const
68 #ifdef ELAST
69 if (ev > ELAST)
70 return string("unspecified generic_category error");
71 #endif // ELAST
72 return __do_message::message(ev);
75 const error_category&
76 generic_category() _NOEXCEPT
78 static __generic_error_category s;
79 return s;
82 class _LIBCPP_HIDDEN __system_error_category
83 : public __do_message
85 public:
86 virtual const char* name() const _NOEXCEPT;
87 virtual string message(int ev) const;
88 virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
91 const char*
92 __system_error_category::name() const _NOEXCEPT
94 return "system";
97 string
98 __system_error_category::message(int ev) const
100 #ifdef ELAST
101 if (ev > ELAST)
102 return string("unspecified system_category error");
103 #endif // ELAST
104 return __do_message::message(ev);
107 error_condition
108 __system_error_category::default_error_condition(int ev) const _NOEXCEPT
110 #ifdef ELAST
111 if (ev > ELAST)
112 return error_condition(ev, system_category());
113 #endif // ELAST
114 return error_condition(ev, generic_category());
117 const error_category&
118 system_category() _NOEXCEPT
120 static __system_error_category s;
121 return s;
124 // error_condition
126 string
127 error_condition::message() const
129 return __cat_->message(__val_);
132 // error_code
134 string
135 error_code::message() const
137 return __cat_->message(__val_);
140 // system_error
142 string
143 system_error::__init(const error_code& ec, string what_arg)
145 if (ec)
147 if (!what_arg.empty())
148 what_arg += ": ";
149 what_arg += ec.message();
151 return _VSTD::move(what_arg);
154 system_error::system_error(error_code ec, const string& what_arg)
155 : runtime_error(__init(ec, what_arg)),
156 __ec_(ec)
160 system_error::system_error(error_code ec, const char* what_arg)
161 : runtime_error(__init(ec, what_arg)),
162 __ec_(ec)
166 system_error::system_error(error_code ec)
167 : runtime_error(__init(ec, "")),
168 __ec_(ec)
172 system_error::system_error(int ev, const error_category& ecat, const string& what_arg)
173 : runtime_error(__init(error_code(ev, ecat), what_arg)),
174 __ec_(error_code(ev, ecat))
178 system_error::system_error(int ev, const error_category& ecat, const char* what_arg)
179 : runtime_error(__init(error_code(ev, ecat), what_arg)),
180 __ec_(error_code(ev, ecat))
184 system_error::system_error(int ev, const error_category& ecat)
185 : runtime_error(__init(error_code(ev, ecat), "")),
186 __ec_(error_code(ev, ecat))
190 system_error::~system_error() _NOEXCEPT
194 void
195 __throw_system_error(int ev, const char* what_arg)
197 #ifndef _LIBCPP_NO_EXCEPTIONS
198 throw system_error(error_code(ev, system_category()), what_arg);
199 #else
200 (void)ev;
201 (void)what_arg;
202 #endif
205 _LIBCPP_END_NAMESPACE_STD