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"
26 void error_set(Error
**errp
, ErrorClass err_class
, const char *fmt
, ...)
34 assert(*errp
== NULL
);
36 err
= g_malloc0(sizeof(*err
));
39 err
->msg
= g_strdup_vprintf(fmt
, ap
);
41 err
->err_class
= err_class
;
46 void error_set_errno(Error
**errp
, int os_errno
, ErrorClass err_class
,
56 assert(*errp
== NULL
);
58 err
= g_malloc0(sizeof(*err
));
61 msg1
= g_strdup_vprintf(fmt
, ap
);
63 err
->msg
= g_strdup_printf("%s: %s", msg1
, strerror(os_errno
));
69 err
->err_class
= err_class
;
74 Error
*error_copy(const Error
*err
)
78 err_new
= g_malloc0(sizeof(*err
));
79 err_new
->msg
= g_strdup(err
->msg
);
80 err_new
->err_class
= err
->err_class
;
85 bool error_is_set(Error
**errp
)
87 return (errp
&& *errp
);
90 ErrorClass
error_get_class(const Error
*err
)
92 return err
->err_class
;
95 const char *error_get_pretty(Error
*err
)
100 void error_free(Error
*err
)
108 void error_propagate(Error
**dst_err
, Error
*local_err
)
110 if (dst_err
&& !*dst_err
) {
111 *dst_err
= local_err
;
112 } else if (local_err
) {
113 error_free(local_err
);