From 730082432a6b03636d28eb8c16fe5fbb7e279466 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 18 Jul 2019 01:20:44 -0400 Subject: image_new(): Support "-" file name for stdout --- (limited to 'src') diff --git a/src/image.c b/src/image.c index d85c9fd..3c5d98f 100644 --- a/src/image.c +++ b/src/image.c @@ -46,10 +46,13 @@ image_new(const char *file_name) return NULL; } - image->fp = fopen(file_name, "wb"); - if (!image->fp) { - printf(_("Error: Cannot open \"%s\" for writing\n"), file_name); - return image_destroy(&image); + if (strcmp(file_name, "-") != 0) { + image->fp = fopen(file_name, "wb"); + if (!image->fp) { + printf(_("Error: Cannot open \"%s\" for writing\n"), + file_name); + return image_destroy(&image); + } } image->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, @@ -63,7 +66,11 @@ image_new(const char *file_name) return image_destroy(&image); } - png_init_io(image->png_ptr, image->fp); + if (image->fp) { + png_init_io(image->png_ptr, image->fp); + } else { + png_init_io(image->png_ptr, stdout); + } return image; } @@ -107,7 +114,9 @@ image_destroy(struct image **image_p) image = *image_p; - fclose(image->fp); + if (image->fp) { + fclose(image->fp); + } png_destroy_write_struct(&image->png_ptr, &image->info_ptr); free(image); return image = NULL; diff --git a/src/image.h b/src/image.h index 1177cd0..b303c23 100644 --- a/src/image.h +++ b/src/image.h @@ -24,6 +24,8 @@ #include "text.h" +#include + #include "font.h" #define IMAGE_BIT_DEPTH 8 -- cgit v0.9.1