WG14 result
Loading...
Searching...
No Matches
status_code_generic.h
Go to the documentation of this file.
1/* Proposed WG14 Result
2(C) 2024 - 2026 Niall Douglas <http://www.nedproductions.biz/>
3File Created: Oct 2025
4
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License in the accompanying file
9Licence.txt or at
10
11http://www.apache.org/licenses/LICENSE-2.0
12
13Unless required by applicable law or agreed to in writing, software
14distributed under the License is distributed on an "AS IS" BASIS,
15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16See the License for the specific language governing permissions and
17limitations under the License.
18*/
19
20#ifndef WG14_RESULT_STATUS_CODE_GENERIC_H
21#define WG14_RESULT_STATUS_CODE_GENERIC_H
22
23#include "status_code_domain.h"
24
25#include <errno.h>
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
33 enum WG14_RESULT_PREFIX(status_code_errc)
34 {
35 WG14_RESULT_PREFIX(status_code_errc_success) = 0,
36 WG14_RESULT_PREFIX(status_code_errc_unknown) = -1,
37
39 EAFNOSUPPORT,
40 WG14_RESULT_PREFIX(status_code_errc_address_in_use) = EADDRINUSE,
41 WG14_RESULT_PREFIX(status_code_errc_address_not_available) = EADDRNOTAVAIL,
42 WG14_RESULT_PREFIX(status_code_errc_already_connected) = EISCONN,
43 WG14_RESULT_PREFIX(status_code_errc_argument_list_too_long) = E2BIG,
44 WG14_RESULT_PREFIX(status_code_errc_argument_out_of_domain) = EDOM,
45 WG14_RESULT_PREFIX(status_code_errc_bad_address) = EFAULT,
46 WG14_RESULT_PREFIX(status_code_errc_bad_file_descriptor) = EBADF,
47 WG14_RESULT_PREFIX(status_code_errc_bad_message) = EBADMSG,
48 WG14_RESULT_PREFIX(status_code_errc_broken_pipe) = EPIPE,
49 WG14_RESULT_PREFIX(status_code_errc_connection_aborted) = ECONNABORTED,
51 EALREADY,
52 WG14_RESULT_PREFIX(status_code_errc_connection_refused) = ECONNREFUSED,
53 WG14_RESULT_PREFIX(status_code_errc_connection_reset) = ECONNRESET,
54 WG14_RESULT_PREFIX(status_code_errc_cross_device_link) = EXDEV,
56 EDESTADDRREQ,
57 WG14_RESULT_PREFIX(status_code_errc_device_or_resource_busy) = EBUSY,
58 WG14_RESULT_PREFIX(status_code_errc_directory_not_empty) = ENOTEMPTY,
59 WG14_RESULT_PREFIX(status_code_errc_executable_format_error) = ENOEXEC,
60 WG14_RESULT_PREFIX(status_code_errc_file_exists) = EEXIST,
61 WG14_RESULT_PREFIX(status_code_errc_file_too_large) = EFBIG,
62 WG14_RESULT_PREFIX(status_code_errc_filename_too_long) = ENAMETOOLONG,
63 WG14_RESULT_PREFIX(status_code_errc_function_not_supported) = ENOSYS,
64 WG14_RESULT_PREFIX(status_code_errc_host_unreachable) = EHOSTUNREACH,
65 WG14_RESULT_PREFIX(status_code_errc_identifier_removed) = EIDRM,
66 WG14_RESULT_PREFIX(status_code_errc_illegal_byte_sequence) = EILSEQ,
68 ENOTTY,
69 WG14_RESULT_PREFIX(status_code_errc_interrupted) = EINTR,
70 WG14_RESULT_PREFIX(status_code_errc_invalid_argument) = EINVAL,
71 WG14_RESULT_PREFIX(status_code_errc_invalid_seek) = ESPIPE,
72 WG14_RESULT_PREFIX(status_code_errc_io_error) = EIO,
73 WG14_RESULT_PREFIX(status_code_errc_is_a_directory) = EISDIR,
74 WG14_RESULT_PREFIX(status_code_errc_message_size) = EMSGSIZE,
75 WG14_RESULT_PREFIX(status_code_errc_network_down) = ENETDOWN,
76 WG14_RESULT_PREFIX(status_code_errc_network_reset) = ENETRESET,
77 WG14_RESULT_PREFIX(status_code_errc_network_unreachable) = ENETUNREACH,
78 WG14_RESULT_PREFIX(status_code_errc_no_buffer_space) = ENOBUFS,
79 WG14_RESULT_PREFIX(status_code_errc_no_child_process) = ECHILD,
80 WG14_RESULT_PREFIX(status_code_errc_no_link) = ENOLINK,
81 WG14_RESULT_PREFIX(status_code_errc_no_lock_available) = ENOLCK,
82 WG14_RESULT_PREFIX(status_code_errc_no_message) = ENOMSG,
83 WG14_RESULT_PREFIX(status_code_errc_no_protocol_option) = ENOPROTOOPT,
84 WG14_RESULT_PREFIX(status_code_errc_no_space_on_device) = ENOSPC,
85 WG14_RESULT_PREFIX(status_code_errc_no_stream_resources) = ENOSR,
86 WG14_RESULT_PREFIX(status_code_errc_no_such_device_or_address) = ENXIO,
87 WG14_RESULT_PREFIX(status_code_errc_no_such_device) = ENODEV,
88 WG14_RESULT_PREFIX(status_code_errc_no_such_file_or_directory) = ENOENT,
89 WG14_RESULT_PREFIX(status_code_errc_no_such_process) = ESRCH,
90 WG14_RESULT_PREFIX(status_code_errc_not_a_directory) = ENOTDIR,
91 WG14_RESULT_PREFIX(status_code_errc_not_a_socket) = ENOTSOCK,
92 WG14_RESULT_PREFIX(status_code_errc_not_a_stream) = ENOSTR,
93 WG14_RESULT_PREFIX(status_code_errc_not_connected) = ENOTCONN,
94 WG14_RESULT_PREFIX(status_code_errc_not_enough_memory) = ENOMEM,
95 WG14_RESULT_PREFIX(status_code_errc_not_supported) = ENOTSUP,
96 WG14_RESULT_PREFIX(status_code_errc_operation_canceled) = ECANCELED,
97 WG14_RESULT_PREFIX(status_code_errc_operation_in_progress) = EINPROGRESS,
98 WG14_RESULT_PREFIX(status_code_errc_operation_not_permitted) = EPERM,
99 WG14_RESULT_PREFIX(status_code_errc_operation_not_supported) = EOPNOTSUPP,
100 WG14_RESULT_PREFIX(status_code_errc_operation_would_block) = EWOULDBLOCK,
101 WG14_RESULT_PREFIX(status_code_errc_owner_dead) = EOWNERDEAD,
102 WG14_RESULT_PREFIX(status_code_errc_permission_denied) = EACCES,
103 WG14_RESULT_PREFIX(status_code_errc_protocol_error) = EPROTO,
104 WG14_RESULT_PREFIX(status_code_errc_protocol_not_supported) =
105 EPROTONOSUPPORT,
106 WG14_RESULT_PREFIX(status_code_errc_read_only_file_system) = EROFS,
108 EDEADLK,
110 EAGAIN,
111 WG14_RESULT_PREFIX(status_code_errc_result_out_of_range) = ERANGE,
112 WG14_RESULT_PREFIX(status_code_errc_state_not_recoverable) =
113 ENOTRECOVERABLE,
114 WG14_RESULT_PREFIX(status_code_errc_stream_timeout) = ETIME,
115 WG14_RESULT_PREFIX(status_code_errc_text_file_busy) = ETXTBSY,
116 WG14_RESULT_PREFIX(status_code_errc_timed_out) = ETIMEDOUT,
118 WG14_RESULT_PREFIX(status_code_errc_too_many_files_open) = EMFILE,
119 WG14_RESULT_PREFIX(status_code_errc_too_many_links) = EMLINK,
121 WG14_RESULT_PREFIX(status_code_errc_value_too_large) = EOVERFLOW,
122 WG14_RESULT_PREFIX(status_code_errc_wrong_protocol_type) = EPROTOTYPE
123 };
124
127 WG14_RESULT_SINGLETON WG14_RESULT_PREFIX(status_code_domain) *
128 WG14_RESULT_PREFIX(status_code_generic_domain)(void);
129
131 typedef struct WG14_RESULT_PREFIX(status_code_generic_s)
132 {
133 WG14_RESULT_PREFIX(status_code_untyped) base;
134 enum WG14_RESULT_PREFIX(status_code_errc) value;
135 } WG14_RESULT_PREFIX(status_code_generic);
136
138 WG14_RESULT_INLINE WG14_RESULT_PREFIX(status_code_generic) WG14_RESULT_PREFIX(
139 status_code_generic_make)(enum WG14_RESULT_PREFIX(status_code_errc) val)
140 {
141 const WG14_RESULT_PREFIX(status_code_generic)
142 ret = {{WG14_RESULT_PREFIX(status_code_generic_domain)()}, val};
143 return ret;
144 }
145
147 struct WG14_RESULT_PREFIX(status_code_domain_vtable_generic_code_args)
148 {
149 WG14_RESULT_PREFIX(status_code_generic) ret;
150 const WG14_RESULT_PREFIX(status_code_untyped) * code;
151 };
152
158 WG14_RESULT_INLINE bool WG14_RESULT_PREFIX(status_code_equivalent)(
159 const WG14_RESULT_PREFIX(status_code_untyped) * primary,
160 const WG14_RESULT_PREFIX(status_code_untyped) * secondary)
161 {
162 if(primary->domain != WG14_RESULT_NULLPTR &&
163 secondary->domain != WG14_RESULT_NULLPTR)
164 {
165 WG14_RESULT_PREFIX(status_code_domain) *const primary_domain =
166 primary->domain;
167 WG14_RESULT_PREFIX(status_code_domain) *const secondary_domain =
168 secondary->domain;
169 if(WG14_RESULT_VTABLE_INVOKE_API(primary_domain, equivalent, primary,
170 secondary))
171 {
172 return true;
173 }
174 if(WG14_RESULT_VTABLE_INVOKE_API(secondary_domain, equivalent, secondary,
175 primary))
176 {
177 return true;
178 }
179 struct WG14_RESULT_PREFIX(status_code_domain_vtable_generic_code_args)
180 args;
181 memset(&args, 0, sizeof(args));
182 args.code = secondary;
183 WG14_RESULT_VTABLE_INVOKE_API(secondary_domain, generic_code, &args);
184 if(args.ret.value != WG14_RESULT_PREFIX(status_code_errc_unknown) &&
185 WG14_RESULT_VTABLE_INVOKE_API(primary->domain, equivalent, primary,
186 &args.ret.base))
187 {
188 return true;
189 }
190 memset(&args, 0, sizeof(args));
191 args.code = primary;
192 WG14_RESULT_VTABLE_INVOKE_API(primary_domain, generic_code, &args);
193 if(args.ret.value != WG14_RESULT_PREFIX(status_code_errc_unknown) &&
194 WG14_RESULT_VTABLE_INVOKE_API(secondary->domain, equivalent, secondary,
195 &args.ret.base))
196 {
197 return true;
198 }
199 }
200 // If we are both empty, we are equivalent
201 if(WG14_RESULT_NULLPTR == primary->domain &&
202 WG14_RESULT_NULLPTR == secondary->domain)
203 {
204 return true; // NOLINT
205 }
206 // Otherwise not equivalent
207 return false;
208 }
209
212 WG14_RESULT_INLINE bool WG14_RESULT_PREFIX(status_code_equivalent_errc)(
213 const WG14_RESULT_PREFIX(status_code_untyped) * primary,
214 enum WG14_RESULT_PREFIX(status_code_errc) errc)
215 {
216 const WG14_RESULT_PREFIX(status_code_generic) secondary =
217 WG14_RESULT_PREFIX(status_code_generic_make)(errc);
218 return WG14_RESULT_PREFIX(status_code_equivalent)(primary, &secondary.base);
219 }
220
226#define status_code_equivalent(primary, secondary) \
227 WG14_RESULT_PREFIX(status_code_equivalent)(&(primary).base, &(secondary).base)
230#define status_code_equivalent_errc(primary, errc) \
231 WG14_RESULT_PREFIX(status_code_equivalent_errc)(&(primary).base, (errc))
232
233
234#ifdef __cplusplus
235}
236#endif
237
238#if WG14_RESULT_ENABLE_HEADER_ONLY
239#include "../../src/wg14_result/status_code_generic.c"
240#endif
241
242#endif
#define WG14_RESULT_NULLPTR
Definition config.h:47
#define WG14_RESULT_INLINE
Definition config.h:63
#define WG14_RESULT_EXTERN
Definition config.h:113
#define WG14_RESULT_SINGLETON
Definition config.h:121
#define WG14_RESULT_VTABLE_INVOKE_API(domain, name,...)
#define status_code_equivalent(primary, secondary)
True if the status codes are semantically equivalent in any way (convenience macro)....
#define status_code_equivalent_errc(primary, errc)
True if the status code is semantically equivalent in any way to the generic enum value (convenience ...
status_code_domain * status_code_generic_domain(void)
Retrieve the domain for status_code_generic
status_code_errc
The generic error coding (POSIX)
@ status_code_errc_invalid_argument
@ status_code_errc_no_buffer_space
@ status_code_errc_not_a_socket
@ status_code_errc_value_too_large
@ status_code_errc_too_many_links
@ status_code_errc_operation_not_permitted
@ status_code_errc_success
@ status_code_errc_read_only_file_system
@ status_code_errc_no_stream_resources
@ status_code_errc_unknown
@ status_code_errc_operation_not_supported
@ status_code_errc_resource_unavailable_try_again
@ status_code_errc_not_a_directory
@ status_code_errc_owner_dead
@ status_code_errc_not_connected
@ status_code_errc_too_many_files_open_in_system
@ status_code_errc_network_reset
@ status_code_errc_host_unreachable
@ status_code_errc_too_many_files_open
@ status_code_errc_io_error
@ status_code_errc_address_not_available
@ status_code_errc_protocol_error
@ status_code_errc_state_not_recoverable
@ status_code_errc_directory_not_empty
@ status_code_errc_cross_device_link
@ status_code_errc_wrong_protocol_type
@ status_code_errc_not_supported
@ status_code_errc_executable_format_error
@ status_code_errc_no_child_process
@ status_code_errc_illegal_byte_sequence
@ status_code_errc_not_enough_memory
@ status_code_errc_file_too_large
@ status_code_errc_identifier_removed
@ status_code_errc_connection_reset
@ status_code_errc_interrupted
@ status_code_errc_is_a_directory
@ status_code_errc_inappropriate_io_control_operation
@ status_code_errc_too_many_symbolic_link_levels
@ status_code_errc_no_lock_available
@ status_code_errc_permission_denied
@ status_code_errc_bad_message
@ status_code_errc_no_such_process
@ status_code_errc_bad_file_descriptor
@ status_code_errc_operation_would_block
@ status_code_errc_file_exists
@ status_code_errc_address_family_not_supported
@ status_code_errc_bad_address
@ status_code_errc_connection_aborted
@ status_code_errc_text_file_busy
@ status_code_errc_timed_out
@ status_code_errc_network_down
@ status_code_errc_no_message
@ status_code_errc_already_connected
@ status_code_errc_argument_out_of_domain
@ status_code_errc_connection_refused
@ status_code_errc_function_not_supported
@ status_code_errc_no_link
@ status_code_errc_operation_canceled
@ status_code_errc_no_such_file_or_directory
@ status_code_errc_no_protocol_option
@ status_code_errc_resource_deadlock_would_occur
@ status_code_errc_no_space_on_device
@ status_code_errc_network_unreachable
@ status_code_errc_no_such_device
@ status_code_errc_result_out_of_range
@ status_code_errc_argument_list_too_long
@ status_code_errc_operation_in_progress
@ status_code_errc_message_size
@ status_code_errc_protocol_not_supported
@ status_code_errc_not_a_stream
@ status_code_errc_connection_already_in_progress
@ status_code_errc_stream_timeout
@ status_code_errc_device_or_resource_busy
@ status_code_errc_destination_address_required
@ status_code_errc_invalid_seek
@ status_code_errc_broken_pipe
@ status_code_errc_filename_too_long
@ status_code_errc_address_in_use
@ status_code_errc_no_such_device_or_address
The functions defined by a status code domain, kept ABI compatible with a C++ vtable.
A generic status code.
status_code_untyped base
enum status_code_errc value
Type of an untyped status code.
status_code_domain * domain