void ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)

{

    int width = pixman_image_get_width(ds->image);

    int height = pixman_image_get_height(ds->image);

    FILE *f;

    int y;

    int ret;

    pixman_image_t *linebuf;



    trace_ppm_save(filename, ds);

    f = fopen(filename, "wb");

    if (!f) {

        error_setg(errp, "failed to open file '%s': %s", filename,

                   strerror(errno));

        return;

    }

    ret = fprintf(f, "P6\n%d %d\n%d\n", width, height, 255);

    if (ret < 0) {

        linebuf = NULL;

        goto write_err;

    }

    linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);

    for (y = 0; y < height; y++) {

        qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y);

        clearerr(f);

        ret = fwrite(pixman_image_get_data(linebuf), 1,

                     pixman_image_get_stride(linebuf), f);

        (void)ret;

        if (ferror(f)) {

            goto write_err;

        }

    }



out:

    qemu_pixman_image_unref(linebuf);

    fclose(f);

    return;



write_err:

    error_setg(errp, "failed to write to file '%s': %s", filename,

               strerror(errno));

    unlink(filename);

    goto out;

}

void ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)

{

    int width = pixman_image_get_width(ds->image);

    int height = pixman_image_get_height(ds->image);

    FILE *f;

    int y;

    int ret;

    pixman_image_t *linebuf;



    trace_ppm_save(filename, ds);

    f = fopen(filename, "wb");

    if (!f) {

        error_setg(errp, "failed to open file '%s': %s", filename,

                   strerror(errno));

        return;

    }

    ret = fprintf(f, "P6\n%d %d\n%d\n", width, height, 255);

    if (ret < 0) {

        linebuf = NULL;

        goto write_err;

    }

    linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);

    for (y = 0; y < height; y++) {

        qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y);

        clearerr(f);

        ret = fwrite(pixman_image_get_data(linebuf), 1,

                     pixman_image_get_stride(linebuf), f);

        (void)ret;

        if (ferror(f)) {

            goto write_err;

        }

    }



out:

    qemu_pixman_image_unref(linebuf);

    fclose(f);

    return;



write_err:

    error_setg(errp, "failed to write to file '%s': %s", filename,

               strerror(errno));

    unlink(filename);

    goto out;

}

void FUNC_0(const char *VAR_0, struct DisplaySurface *VAR_1, Error **VAR_2)

{

    int VAR_3 = pixman_image_get_width(VAR_1->image);

    int VAR_4 = pixman_image_get_height(VAR_1->image);

    FILE *f;

    int VAR_5;

    int VAR_6;

    pixman_image_t *linebuf;



    trace_ppm_save(VAR_0, VAR_1);

    f = fopen(VAR_0, "wb");

    if (!f) {

        error_setg(VAR_2, "failed to open file '%s': %s", VAR_0,

                   strerror(errno));

        return;

    }

    VAR_6 = fprintf(f, "P6\n%d %d\n%d\n", VAR_3, VAR_4, 255);

    if (VAR_6 < 0) {

        linebuf = NULL;

        goto write_err;

    }

    linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, VAR_3);

    for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) {

        qemu_pixman_linebuf_fill(linebuf, VAR_1->image, VAR_3, 0, VAR_5);

        clearerr(f);

        VAR_6 = fwrite(pixman_image_get_data(linebuf), 1,

                     pixman_image_get_stride(linebuf), f);

        (void)VAR_6;

        if (ferror(f)) {

            goto write_err;

        }

    }



out:

    qemu_pixman_image_unref(linebuf);

    fclose(f);

    return;



write_err:

    error_setg(VAR_2, "failed to write to file '%s': %s", VAR_0,

               strerror(errno));

    unlink(VAR_0);

    goto out;

}

void FUNC_0(const char *VAR_0, struct DisplaySurface *VAR_1, Error **VAR_2)
{ int VAR_3 = pixman_image_get_width(VAR_1->image); int VAR_4 = pixman_image_get_height(VAR_1->image); FILE *f; int VAR_5; int VAR_6; pixman_image_t *linebuf; trace_ppm_save(VAR_0, VAR_1); f = fopen(VAR_0, "wb"); if (!f) { error_setg(VAR_2, "failed to open file '%s': %s", VAR_0,
strerror(errno)); return; } VAR_6 = fprintf(f, "P6\n%d %d\n%d\n", VAR_3, VAR_4, 255); if (VAR_6 < 0) { linebuf = NULL; goto write_err; } linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, VAR_3); for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { qemu_pixman_linebuf_fill(linebuf, VAR_1->image, VAR_3, 0, VAR_5); clearerr(f); VAR_6 = fwrite(pixman_image_get_data(linebuf), 1,
pixman_image_get_stride(linebuf), f); (void)VAR_6; if (ferror(f)) { goto write_err; } } out:
qemu_pixman_image_unref(linebuf); fclose(f); return; write_err:
error_setg(VAR_2, "failed to write to file '%s': %s", VAR_0,
strerror(errno)); unlink(VAR_0); goto out; }