Later in the patch series we will use this function a few times. This will avoid duplicating the code.
Signed-off-by: Pavel Hrdina <phrd...@redhat.com> --- qemu-img.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index cd096a1..ab83fbe 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -322,6 +322,16 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list, return 0; } +static int qemu_img_handle_error(Error *err) +{ + if (error_is_set(&err)) { + error_report("%s", error_get_pretty(err)); + error_free(err); + return 1; + } + return 0; +} + static int img_create(int argc, char **argv) { int c; @@ -400,13 +410,8 @@ static int img_create(int argc, char **argv) bdrv_img_create(filename, fmt, base_filename, base_fmt, options, img_size, BDRV_O_FLAGS, &local_err, quiet); - if (error_is_set(&local_err)) { - error_report("%s", error_get_pretty(local_err)); - error_free(local_err); - return 1; - } - return 0; + return qemu_img_handle_error(local_err); } static void dump_json_image_check(ImageCheck *check, bool quiet) -- 1.8.1.4