1 // SPDX-FileCopyrightText: Copyright 2012 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
10 #if defined(__clang__)
11 #define WCORE_PRINTFLIKE(f, a) __attribute__((format(printf, f, a)))
12 #elif defined(__GNUC__)
13 #define WCORE_PRINTFLIKE(f, a) __attribute__((format(gnu_printf, f, a)))
15 #define WCORE_PRINTFLIKE(f, a)
22 /// @brief Thread-local info for the wcore_error module.
23 struct wcore_error_tinfo
;
25 struct wcore_error_tinfo
*
26 wcore_error_tinfo_create(void);
29 wcore_error_tinfo_destroy(struct wcore_error_tinfo
*self
);
31 /// @brief Reset the error state to WAFFLE_NO_ERROR.
33 wcore_error_reset(void);
35 /// @brief Set error code for client.
37 /// @param error is an `enum waffle_error`.
39 wcore_error(enum waffle_error error
);
41 /// @brief Set error code and message for client.
43 /// @param error is an `enum waffle_error`.
44 /// @param format may be null.
45 void WCORE_PRINTFLIKE(2, 3)
46 wcore_errorf(enum waffle_error error
, const char *format
, ...);
48 /// @brief Emit error for errno.
50 /// Set error code to WAFFLE_ERROR_UNKNOWN and place the output of
51 /// strerror() in the error message. If \a format is not null,
52 /// then prepend the strerror() message with "${format}: ".
53 void WCORE_PRINTFLIKE(1, 2)
54 wcore_error_errno(const char *format
, ...);
56 /// @brief Emit WAFFLE_ERROR_BAD_ATTRIBUTE with a default error message.
58 wcore_error_bad_attribute(intptr_t attr
);
60 /// @brief Set error to WAFFLE_INTERNAL_ERROR with source location.
61 #define wcore_error_internal(format, ...) \
62 _wcore_error_internal(__FILE__, __LINE__, format, __VA_ARGS__)
64 /// @brief Execute a statement with errors disabled.
65 #define WCORE_ERROR_DISABLED(statement) \
67 _wcore_error_disable(); \
69 _wcore_error_enable(); \
72 /// @brief Get the last set error code.
74 wcore_error_get_code(void);
76 /// @brief Get the user-visible portion of the error state.
77 const struct waffle_error_info
*
78 wcore_error_get_info(void);
80 void WCORE_PRINTFLIKE(3, 4)
81 _wcore_error_internal(const char *file
, int line
, const char *format
, ...);
83 void _wcore_error_enable(void);
84 void _wcore_error_disable(void);