]>
Commit | Line | Data |
---|---|---|
d5ec4f27 LC |
1 | /* |
2 | * QEMU Error Objects | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU LGPL, version 2. See | |
10 | * the COPYING.LIB file in the top-level directory. | |
11 | */ | |
12 | #ifndef ERROR_H | |
13 | #define ERROR_H | |
14 | ||
1de7afc9 | 15 | #include "qemu/compiler.h" |
13f59ae8 | 16 | #include "qapi-types.h" |
d5ec4f27 LC |
17 | #include <stdbool.h> |
18 | ||
19 | /** | |
df1e608a LC |
20 | * A class representing internal errors within QEMU. An error has a ErrorClass |
21 | * code and a human message. | |
d5ec4f27 LC |
22 | */ |
23 | typedef struct Error Error; | |
24 | ||
25 | /** | |
df1e608a LC |
26 | * Set an indirect pointer to an error given a ErrorClass value and a |
27 | * printf-style human message. This function is not meant to be used outside | |
28 | * of QEMU. | |
d5ec4f27 | 29 | */ |
64dfefed MA |
30 | void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) |
31 | GCC_FMT_ATTR(3, 4); | |
d5ec4f27 | 32 | |
680d16dc PB |
33 | /** |
34 | * Set an indirect pointer to an error given a ErrorClass value and a | |
35 | * printf-style human message, followed by a strerror() string if | |
36 | * @os_error is not zero. | |
37 | */ | |
4463dcb8 MA |
38 | void error_setg_errno(Error **errp, int os_error, const char *fmt, ...) |
39 | GCC_FMT_ATTR(3, 4); | |
680d16dc | 40 | |
20840d4c TS |
41 | #ifdef _WIN32 |
42 | /** | |
43 | * Set an indirect pointer to an error given a ErrorClass value and a | |
44 | * printf-style human message, followed by a g_win32_error_message() string if | |
45 | * @win32_err is not zero. | |
46 | */ | |
e7cf59e8 MA |
47 | void error_setg_win32(Error **errp, int win32_err, const char *fmt, ...) |
48 | GCC_FMT_ATTR(3, 4); | |
20840d4c TS |
49 | #endif |
50 | ||
75d789f8 LC |
51 | /** |
52 | * Same as error_set(), but sets a generic error | |
53 | */ | |
a9499ddd MA |
54 | void error_setg(Error **errp, const char *fmt, ...) |
55 | GCC_FMT_ATTR(2, 3); | |
75d789f8 | 56 | |
54028d75 LC |
57 | /** |
58 | * Helper for open() errors | |
59 | */ | |
60 | void error_setg_file_open(Error **errp, int os_errno, const char *filename); | |
61 | ||
ea25fbca LC |
62 | /* |
63 | * Get the error class of an error object. | |
64 | */ | |
65 | ErrorClass error_get_class(const Error *err); | |
66 | ||
79020cfc LC |
67 | /** |
68 | * Returns an exact copy of the error passed as an argument. | |
69 | */ | |
70 | Error *error_copy(const Error *err); | |
71 | ||
d5ec4f27 LC |
72 | /** |
73 | * Get a human readable representation of an error object. | |
74 | */ | |
75 | const char *error_get_pretty(Error *err); | |
76 | ||
2ee2f1e4 MA |
77 | /** |
78 | * Convenience function to error_report() and free an error object. | |
79 | */ | |
80 | void error_report_err(Error *); | |
81 | ||
d5ec4f27 LC |
82 | /** |
83 | * Propagate an error to an indirect pointer to an error. This function will | |
84 | * always transfer ownership of the error reference and handles the case where | |
d195325b | 85 | * dst_err is NULL correctly. Errors after the first are discarded. |
d5ec4f27 | 86 | */ |
64dfefed | 87 | void error_propagate(Error **dst_errp, Error *local_err); |
d5ec4f27 LC |
88 | |
89 | /** | |
90 | * Free an error object. | |
91 | */ | |
92 | void error_free(Error *err); | |
93 | ||
5d24ee70 PC |
94 | /** |
95 | * If passed to error_set and friends, abort(). | |
96 | */ | |
97 | ||
98 | extern Error *error_abort; | |
99 | ||
d5ec4f27 | 100 | #endif |