diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-18 01:20:44 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-18 01:20:44 (EDT) |
commit | 730082432a6b03636d28eb8c16fe5fbb7e279466 (patch) | |
tree | 594cef343cc824443ead4e3a1c3ee6ec24ac17ea /src | |
parent | 16148abf5eac0e52464ab0fc589c805728790dd2 (diff) |
image_new(): Support "-" file name for stdout
Diffstat (limited to 'src')
-rw-r--r-- | src/image.c | 21 | ||||
-rw-r--r-- | src/image.h | 2 |
2 files changed, 17 insertions, 6 deletions
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 <string.h> + #include "font.h" #define IMAGE_BIT_DEPTH 8 |