]>
git.proxmox.com Git - qemu.git/blob - error.c
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
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.
13 #include "qemu-common.h"
17 #include "qapi-types.h"
27 void error_set(Error
**errp
, ErrorClass err_class
, const char *fmt
, ...)
35 assert(*errp
== NULL
);
37 err
= g_malloc0(sizeof(*err
));
40 err
->obj
= qobject_to_qdict(qobject_from_jsonv(fmt
, &ap
));
42 err
->msg
= qerror_format(fmt
, err
->obj
);
43 err
->err_class
= err_class
;
48 Error
*error_copy(const Error
*err
)
52 err_new
= g_malloc0(sizeof(*err
));
53 err_new
->msg
= g_strdup(err
->msg
);
54 err_new
->err_class
= err
->err_class
;
55 err_new
->obj
= err
->obj
;
56 QINCREF(err_new
->obj
);
61 bool error_is_set(Error
**errp
)
63 return (errp
&& *errp
);
66 ErrorClass
error_get_class(const Error
*err
)
68 return err
->err_class
;
71 const char *error_get_pretty(Error
*err
)
76 void error_free(Error
*err
)
85 void error_propagate(Error
**dst_err
, Error
*local_err
)
87 if (dst_err
&& !*dst_err
) {
89 } else if (local_err
) {
90 error_free(local_err
);