]> git.proxmox.com Git - qemu.git/blame - include/qapi/error.h
sun4m: Add FCode ROM for TCX framebuffer
[qemu.git] / include / qapi / error.h
CommitLineData
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 */
23typedef 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 */
13f59ae8 30void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
d5ec4f27 31
680d16dc
PB
32/**
33 * Set an indirect pointer to an error given a ErrorClass value and a
34 * printf-style human message, followed by a strerror() string if
35 * @os_error is not zero.
36 */
37void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5);
38
20840d4c
TS
39#ifdef _WIN32
40/**
41 * Set an indirect pointer to an error given a ErrorClass value and a
42 * printf-style human message, followed by a g_win32_error_message() string if
43 * @win32_err is not zero.
44 */
45void error_set_win32(Error **err, int win32_err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5);
46#endif
47
75d789f8
LC
48/**
49 * Same as error_set(), but sets a generic error
50 */
51#define error_setg(err, fmt, ...) \
52 error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
680d16dc
PB
53#define error_setg_errno(err, os_error, fmt, ...) \
54 error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
20840d4c
TS
55#ifdef _WIN32
56#define error_setg_win32(err, win32_err, fmt, ...) \
57 error_set_win32(err, win32_err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
58#endif
75d789f8 59
54028d75
LC
60/**
61 * Helper for open() errors
62 */
63void error_setg_file_open(Error **errp, int os_errno, const char *filename);
64
d5ec4f27
LC
65/**
66 * Returns true if an indirect pointer to an error is pointing to a valid
67 * error object.
68 */
69bool error_is_set(Error **err);
70
ea25fbca
LC
71/*
72 * Get the error class of an error object.
73 */
74ErrorClass error_get_class(const Error *err);
75
79020cfc
LC
76/**
77 * Returns an exact copy of the error passed as an argument.
78 */
79Error *error_copy(const Error *err);
80
d5ec4f27
LC
81/**
82 * Get a human readable representation of an error object.
83 */
84const char *error_get_pretty(Error *err);
85
d5ec4f27
LC
86/**
87 * Propagate an error to an indirect pointer to an error. This function will
88 * always transfer ownership of the error reference and handles the case where
d195325b 89 * dst_err is NULL correctly. Errors after the first are discarded.
d5ec4f27
LC
90 */
91void error_propagate(Error **dst_err, Error *local_err);
92
93/**
94 * Free an error object.
95 */
96void error_free(Error *err);
97
d5ec4f27 98#endif