cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
cwist_err.h
Go to the documentation of this file.
1
8#ifndef __CWIST_ERR_H__
9#define __CWIST_ERR_H__
10
11#include <stdint.h>
12#include <stdbool.h>
13#include <cjson/cJSON.h>
14
16struct cwist_sstring;
17
22typedef enum cwist_errtype_t {
23 /* --- Signed Integer Types --- */
28#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
29 CWIST_ERR_INT128,
30#endif
31
32 /* --- Unsigned Integer Types --- */
37#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
38 CWIST_ERR_UINT128,
39#endif
40
41 /* --- Complex Types --- */
47
52typedef struct __prim_cwist_error_t {
53 /* Signed representations */
54 int8_t err_i8;
55 int16_t err_i16;
56 int32_t err_i32;
57 int64_t err_i64;
58#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
59 __int128 err_i128;
60#endif
61
62 /* Unsigned representations */
63 uint8_t err_u8;
64 uint16_t err_u16;
65 uint32_t err_u32;
66 uint64_t err_u64;
67#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
68 unsigned __int128 err_u128;
69#endif
70
72 cJSON *err_json;
74
79typedef struct cwist_error_t {
83
94static inline bool cwist_error_is_ok(const cwist_error_t *err) {
95 if (!err) return true;
96 switch (err->errtype) {
97 case CWIST_ERR_INT8: return err->error.err_i8 == 0;
98 case CWIST_ERR_INT16: return err->error.err_i16 == 0;
99 case CWIST_ERR_INT32: return err->error.err_i32 == 0;
100 case CWIST_ERR_INT64: return err->error.err_i64 == 0;
101#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
102 case CWIST_ERR_INT128: return err->error.err_i128 == 0;
103#endif
104 case CWIST_ERR_UINT8: return err->error.err_u8 == 0;
105 case CWIST_ERR_UINT16: return err->error.err_u16 == 0;
106 case CWIST_ERR_UINT32: return err->error.err_u32 == 0;
107 case CWIST_ERR_UINT64: return err->error.err_u64 == 0;
108#if (defined(__clang__) || defined(__GNUC__)) && defined(USE_128BIT_ERRCODE)
109 case CWIST_ERR_UINT128: return err->error.err_u128 == 0;
110#endif
111 case CWIST_ERR_STRING: return err->error.err_string == NULL;
112 case CWIST_ERR_JSON: return err->error.err_json == NULL;
113 default: return false;
114 }
115}
116
117/* --- Function Prototypes --- */
118
125
136
143
144/* --- Generic Error Macros --- */
145
149#define CWIST_SUCCESS 0
150#define CWIST_FAILURE -1
151#define CWIST_ERROR_IO -2
152#define CWIST_ERROR_NOMEM -3
153#define CWIST_ERROR_INVALID_PARAM -4
154#define CWIST_ERROR_PROTOCOL -5
155#define CWIST_ERROR_TIMEOUT -6
158#endif /* __CWIST_ERR_H__ */
cwist_errtype_t
Definition cwist_err.h:13
@ CWIST_ERR_FLOAT
Definition cwist_err.h:40
@ CWIST_ERR_UINT64
Definition cwist_err.h:30
@ CWIST_ERR_STRING
string types
Definition cwist_err.h:36
@ CWIST_ERR_INT16
used when checking common errcodes in Unix/Linux
Definition cwist_err.h:16
@ CWIST_ERR_UINT8
mostly used as 'byte'
Definition cwist_err.h:25
@ CWIST_ERR_DOUBLE
Definition cwist_err.h:41
@ CWIST_ERR_INT8
mostly used to check a char
Definition cwist_err.h:15
@ CWIST_ERR_JSON
Definition cwist_err.h:37
@ CWIST_ERR_INT64
Definition cwist_err.h:20
@ CWIST_ERR_UINT32
Definition cwist_err.h:27
@ CWIST_ERR_INT32
Definition cwist_err.h:17
@ CWIST_ERR_UINT16
Definition cwist_err.h:26
bool cwist_error_is_ok_extern(const cwist_error_t *err)
Out-of-line cwist_error_is_ok(); see include/cwist/sys/err/cwist_err.h.
Definition error.c:30
struct cwist_error_t cwist_error_t
cwist_error_t make_error(cwist_errtype_t type)
Creates an error object initialized with the specified type.
Definition error.c:14
struct __prim_cwist_error_t __prim_cwist_error_t
Internal union-like structure to store the actual error value.
Definition cwist_err.h:44
struct cwist_sstring * err_string
Definition cwist_err.h:67
Integrated error structure used throughout the system.
Definition cwist_err.h:72
cwist_errtype_t errtype
Definition cwist_err.h:73
__prim_cwist_error_t error
Definition cwist_err.h:74
void cwist_error_dispose(cwist_error_t *err)
Release resources owned by an error value. Currently only CWIST_ERR_JSON owns memory (the cJSON paylo...
Definition error.c:43