tree: drop clang-format off for attributes
[mesa-waffle.git] / src / waffle / core / wcore_error.h
blobddfbbff1b63a8aab5e460e68abee776c7f090c94
1 // SPDX-FileCopyrightText: Copyright 2012 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
4 #pragma once
6 #include <stdbool.h>
8 #include "waffle.h"
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)))
14 #else
15 #define WCORE_PRINTFLIKE(f, a)
16 #endif
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
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);
28 bool
29 wcore_error_tinfo_destroy(struct wcore_error_tinfo *self);
31 /// @brief Reset the error state to WAFFLE_NO_ERROR.
32 void
33 wcore_error_reset(void);
35 /// @brief Set error code for client.
36 ///
37 /// @param error is an `enum waffle_error`.
38 void
39 wcore_error(enum waffle_error error);
41 /// @brief Set error code and message for client.
42 ///
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.
49 ///
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.
57 void
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) \
66 do { \
67 _wcore_error_disable(); \
68 statement \
69 _wcore_error_enable(); \
70 } while (0)
72 /// @brief Get the last set error code.
73 enum waffle_error
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);
86 #ifdef __cplusplus
88 #endif