Debian Codegraph @

src/util/error.h

raw
1 #pragma once
2
3 /*
4 * Error Handling
5 *
6 * All our API calls return integers to signal errors or success. Negative
7 * error-codes are fatal errors that the caller should forward unchanged.
8 * Positive error-codes are API errors that have documented behavior and must
9 * be caught and handled by the caller.
10 */
11
12 #include <c-stdaux.h>
13 #include <stdlib.h>
14
15 int error_slow_origin(int r, const char *function, const char *file, int line);
16 int error_slow_trace(int r, const char *function, const char *file, int line);
17 int error_slow_fold(int r, const char *function, const char *file, int line);
18
19 /**
20 * error_origin() - fast-path of error_slow_origin()
21 * @r: error code
22 *
23 * This is the fast-path of error_slow_origin(). See its description for
24 * details.
25 *
26 * Return: 0 or negative error code, depending on @r.
27 */
28 #define error_origin(r) C_CC_MACRO1(ERROR_ORIGIN, (r))
29 #define ERROR_ORIGIN(r) (_c_likely_(!r) ? 0 : error_slow_origin(r, __func__, __FILE__, __LINE__))
30
31 /**
32 * error_trace() - fast-path of error_slow_trace()
33 * @r: error code
34 *
35 * This is the fast-path of error_slow_trace(). See its description for
36 * details.
37 *
38 * Return: @r is returned.
39 */
40 #define error_trace(r) C_CC_MACRO1(ERROR_TRACE, (r))
41 #define ERROR_TRACE(r) (_c_likely_(r >= 0) ? r : error_slow_trace(r, __func__, __FILE__, __LINE__))
42
43 /**
44 * error_fold() - fast-path of error_slow_fold()
45 * @r: error code
46 *
47 * This is the fast-path of error_slow_fold(). See its description for
48 * details.
49 *
50 * Return: 0 or negative error code, depending on @r.
51 */
52 #define error_fold(r) C_CC_MACRO1(ERROR_FOLD, (r))
53 #define ERROR_FOLD(r) (_c_likely_(!r) ? 0 : error_slow_fold(r, __func__, __FILE__, __LINE__))