--- hw/vga.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/hw/vga.c b/hw/vga.c index 5994f43..24af4a1 100644 --- a/hw/vga.c +++ b/hw/vga.c @@ -2364,19 +2364,20 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory) int ppm_save(const char *filename, struct DisplaySurface *ds) { - FILE *f; + QEMUFile *f; uint8_t *d, *d1; uint32_t v; int y, x; uint8_t r, g, b; - int ret; char *linebuf, *pbuf; + gchar *header; + + f = qemu_fopen(filename, "wb"); + g_return_val_if_fail(f != NULL, -1); + + header = g_strdup_printf("P6\n%d %d\n%d\n", ds->width, ds->height, 255); + qemu_put_buffer(f, (uint8_t*)header, strlen(header)); - f = fopen(filename, "wb"); - if (!f) - return -1; - fprintf(f, "P6\n%d %d\n%d\n", - ds->width, ds->height, 255); linebuf = g_malloc(ds->width * 3); d1 = ds->data; for(y = 0; y < ds->height; y++) { @@ -2397,11 +2398,12 @@ int ppm_save(const char *filename, struct DisplaySurface *ds) d += ds->pf.bytes_per_pixel; } d1 += ds->linesize; - ret = fwrite(linebuf, 1, pbuf - linebuf, f); - (void)ret; + qemu_put_buffer(f, (uint8_t*)linebuf, pbuf - linebuf); } + g_free(linebuf); - fclose(f); + g_free(header); + qemu_fclose(f); return 0; } -- 1.7.7.6