]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/std/system_error
acinclude.m4 (GLIBCXX_CHECK_SYSTEM_ERROR): Add ENOLINK, EPROTO for netbsd.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / system_error
1 // <system_error> -*- C++ -*-
2
3 // Copyright (C) 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file include/system_error
31 * This is a Standard C++ Library header.
32 */
33
34 #ifndef _GLIBCXX_SYSTEM_ERROR
35 #define _GLIBCXX_SYSTEM_ERROR 1
36
37 #pragma GCC system_header
38
39 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 # include <c++0x_warning.h>
41 #endif
42
43 #include <bits/c++config.h>
44 #include <cerrno>
45 #include <iosfwd>
46 #include <stdexcept>
47
48 _GLIBCXX_BEGIN_NAMESPACE(std)
49
50 class system_error;
51 class error_code;
52 class error_category;
53
54 extern const error_category& system_category;
55
56 enum posix_errno
57 {
58 address_family_not_supported = EAFNOSUPPORT,
59 address_in_use = EADDRINUSE,
60 address_not_available = EADDRNOTAVAIL,
61 already_connected = EISCONN,
62 argument_list_too_long = E2BIG,
63 argument_out_of_domain = EDOM,
64 bad_address = EFAULT,
65 bad_file_descriptor = EBADF,
66 bad_message = EBADMSG,
67 broken_pipe = EPIPE,
68 connection_aborted = ECONNABORTED,
69 connection_already_in_progress = EALREADY,
70 connection_refused = ECONNREFUSED,
71 connection_reset = ECONNRESET,
72 cross_device_link = EXDEV,
73 destination_address_required = EDESTADDRREQ,
74 device_or_resource_busy = EBUSY,
75 directory_not_empty = ENOTEMPTY,
76 executable_format_error = ENOEXEC,
77 file_exists = EEXIST,
78 file_too_large = EFBIG,
79 filename_too_long = ENAMETOOLONG,
80 function_not_supported = ENOSYS,
81 host_unreachable = EHOSTUNREACH,
82 identifier_removed = EIDRM,
83 illegal_byte_sequence = EILSEQ,
84 inappropriate_io_control_operation = ENOTTY,
85 interrupted = EINTR,
86 invalid_argument = EINVAL,
87 invalid_seek = ESPIPE,
88 io_error = EIO,
89 is_a_directory = EISDIR,
90 message_size = EMSGSIZE,
91 network_down = ENETDOWN,
92 network_reset = ENETRESET,
93 network_unreachable = ENETUNREACH,
94 no_buffer_space = ENOBUFS,
95 no_child_process = ECHILD,
96 #ifdef _GLIBCXX_HAVE_ENOLINK
97 no_link = ENOLINK,
98 #endif
99 no_lock_available = ENOLCK,
100 no_message_available = ENODATA,
101 no_message = ENOMSG,
102 no_protocol_option = ENOPROTOOPT,
103 no_space_on_device = ENOSPC,
104 no_stream_resources = ENOSR,
105 no_such_device_or_address = ENXIO,
106 no_such_device = ENODEV,
107 no_such_file_or_directory = ENOENT,
108 no_such_process = ESRCH,
109 not_a_directory = ENOTDIR,
110 not_a_socket = ENOTSOCK,
111 not_a_stream = ENOSTR,
112 not_connected = ENOTCONN,
113 not_enough_memory = ENOMEM,
114 not_supported = ENOTSUP,
115 operation_canceled = ECANCELED,
116 operation_in_progress = EINPROGRESS,
117 operation_not_permitted = EPERM,
118 operation_not_supported = EOPNOTSUPP,
119 operation_would_block = EWOULDBLOCK,
120 #ifdef _GLIBCXX_HAVE_EOWNERDEAD
121 owner_dead = EOWNERDEAD,
122 #endif
123 permission_denied = EACCES,
124 #ifdef _GLIBCXX_HAVE_EPROTO
125 protocol_error = EPROTO,
126 #endif
127 protocol_not_supported = EPROTONOSUPPORT,
128 read_only_file_system = EROFS,
129 resource_deadlock_would_occur = EDEADLK,
130 resource_unavailable_try_again = EAGAIN,
131 result_out_of_range = ERANGE,
132 #ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE
133 state_not_recoverable = ENOTRECOVERABLE,
134 #endif
135 stream_timeout = ETIME,
136 text_file_busy = ETXTBSY,
137 timed_out = ETIMEDOUT,
138 too_many_files_open_in_system = ENFILE,
139 too_many_files_open = EMFILE,
140 too_many_links = EMLINK,
141 too_many_synbolic_link_levels = ELOOP,
142 value_too_large = EOVERFLOW,
143 wrong_protocol_type = EPROTOTYPE,
144 no_posix_equivalent = 1L << 16
145 };
146
147 struct error_category
148 {
149 error_category() { }
150
151 bool
152 operator==(const error_category& __other) const
153 { return this == &__other; }
154
155 bool
156 operator!=(const error_category& __other) const
157 { return this != &__other; }
158
159 virtual posix_errno
160 posix(int __v) const = 0;
161
162 virtual const string&
163 name() const = 0;
164
165 private:
166 error_category(const error_category&);
167
168 error_category&
169 operator=(const error_category&);
170 };
171
172 struct error_code
173 {
174 error_code() throw()
175 : _M_value(0), _M_cat(&system_category) { }
176
177 error_code(int __v, const error_category& __cat) throw()
178 : _M_value(__v), _M_cat(&__cat) { }
179
180 error_code(posix_errno __v)
181 : _M_value(__v), _M_cat(&system_category) { }
182
183 void
184 assign(int __v, const error_category& __cat) throw()
185 {
186 _M_value = __v;
187 _M_cat = &__cat;
188 }
189
190 void
191 clear() throw()
192 {
193 _M_value = 0;
194 _M_cat = &system_category;
195 }
196
197 int
198 value() const throw() { return _M_value; }
199
200 const error_category&
201 category() const { return *_M_cat; }
202
203 posix_errno
204 posix() const throw() { return this->category().posix(_M_value); }
205
206 // Safe bool idiom.
207 // explicit operator bool() const throw()
208 // { return _M_value != 0; }
209 typedef void (*__bool_type)();
210
211 static void __not_bool_type() { }
212
213 operator __bool_type() const throw()
214 { return _M_value != 0 ? &__not_bool_type : false; }
215
216 bool operator==(const error_code& __other) const
217 { return value() == __other.value() && category() == __other.category(); }
218
219 bool operator!=(const error_code& __other) const
220 { return !(this == &__other); }
221
222 private:
223 int _M_value;
224 const error_category* _M_cat;
225 };
226
227 class system_error : public std::runtime_error
228 {
229 private:
230 error_code _M_code;
231
232 public:
233 system_error(const string& __what, error_code __ec = error_code())
234 : runtime_error(__what), _M_code(__ec) { }
235
236 system_error(const string& __what, int __v, const error_category& __ecat)
237 : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
238
239 virtual ~system_error() throw();
240
241 const error_code&
242 code() const throw() { return _M_code; }
243 };
244
245 _GLIBCXX_END_NAMESPACE
246
247 #endif
248