WG14 result
Loading...
Searching...
No Matches
status_code_system.h
Go to the documentation of this file.
1/* Proposed WG14 Result
2(C) 2024 - 2026 Niall Douglas <http://www.nedproductions.biz/>
3File Created: Nov 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_SYSTEM_H
21#define WG14_RESULT_STATUS_CODE_SYSTEM_H
22
23#include "status_code_generic.h"
24
25#include <stdint.h> // for intptr_t
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
34 typedef struct WG14_RESULT_PREFIX(status_code_system_s)
35 {
36 WG14_RESULT_PREFIX(status_code_untyped) base;
37 intptr_t value;
38 } WG14_RESULT_PREFIX(status_code_system);
39
40 //| \brief An empty `status_code_system`
41 static WG14_RESULT_CONSTEXPR_OR_CONST WG14_RESULT_PREFIX(status_code_system)
42 WG14_RESULT_PREFIX(status_code_system_empty);
43
47 WG14_RESULT_INLINE WG14_RESULT_PREFIX(status_code_system)
48 WG14_RESULT_PREFIX(status_code_system_make)(
49 const WG14_RESULT_PREFIX(status_code_untyped) * src,
50 WG14_RESULT_PREFIX(status_code_domain_payload_info_t) dstinfo)
51 {
52 WG14_RESULT_PREFIX(status_code_system)
53 ret;
54 if(dstinfo.total_size > sizeof(ret))
55 {
57 "status_code_with_payload_system_make cannot make a system code sized "
58 "%zu from an input status code sized %zu.",
59 sizeof(ret), dstinfo.total_size);
60 }
61 if(dstinfo.total_alignment > __alignof(ret))
62 {
64 "status_code_with_payload_system_make cannot make a system code aligned "
65 "%zu from an input status code aligned %zu.",
66 __alignof(ret), dstinfo.total_alignment);
67 }
68 memcpy(&ret, src, dstinfo.total_size);
69 return ret;
70 }
71
73 WG14_RESULT_INLINE WG14_RESULT_PREFIX(status_code_system)
74 WG14_RESULT_PREFIX(status_code_system_make_from_errc)(
75 enum WG14_RESULT_PREFIX(status_code_errc) errc)
76 {
77 const union
78 {
79 WG14_RESULT_PREFIX(status_code_generic) gen;
80 WG14_RESULT_PREFIX(status_code_system) sys;
81 } ret = {WG14_RESULT_PREFIX(status_code_generic_make)(errc)};
82 return ret.sys;
83 }
84
85#define STATUS_CODE_SYSTEM_MAKE_IMPL2(src, payload_size, total_size, \
86 total_alignment) \
87 WG14_RESULT_PREFIX(status_code_system_make) \
88 (WG14_RESULT_STATIC_ASSERT_WITHIN_EXPR( \
89 (total_size) <= sizeof(WG14_RESULT_PREFIX(status_code_system)), \
90 "cannot make a system code from a larger sized input", \
91 WG14_RESULT_STATIC_ASSERT_WITHIN_EXPR( \
92 (total_alignment) <= __alignof(WG14_RESULT_PREFIX(status_code_system)), \
93 "cannot make a system code from a more over aligned input", (src))), \
94 WG14_RESULT_PREFIX(status_code_domain_payload_info_make)( \
95 (payload_size), (total_size), (total_alignment)))
96#define STATUS_CODE_SYSTEM_MAKE_IMPL(src, ...) \
97 STATUS_CODE_SYSTEM_MAKE_IMPL2((src), __VA_ARGS__)
98
102#define status_code_system_make(...) \
103 STATUS_CODE_SYSTEM_MAKE_IMPL( \
104 &(__VA_ARGS__).base, STATUS_CODE_DOMAIN_PAYLOAD_INFO_INIT_INNARDS( \
105 WG14_RESULT_TYPEOF_UNQUAL((__VA_ARGS__).value)))
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif
#define WG14_RESULT_INLINE
Definition config.h:63
#define WG14_RESULT_CONSTEXPR_OR_CONST
Definition config.h:91
#define WG14_RESULT_ABORTF(...)
Definition config.h:179
status_code_errc
The generic error coding (POSIX)
#define status_code_system_make(...)
Make a system code from a typed input status code, this will fail if the input status cannot fit into...
Type of a payload info of a domain.
A generic status code.
A status_code guaranteed to be able to hold any system error code in full. The payload is always an i...
status_code_untyped base
Type of an untyped status code.