From 290aa13ddd8d05bde86f14a82cd76c18b4b8f082 Mon Sep 17 00:00:00 2001 From: jvech Date: Wed, 21 Jun 2023 20:23:29 -0500 Subject: add: CLI support added --- src/ppm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/ppm.c') diff --git a/src/ppm.c b/src/ppm.c index a5cf3fe..a868b76 100644 --- a/src/ppm.c +++ b/src/ppm.c @@ -9,7 +9,8 @@ ppm_write(const char *file, Image *img) /* * Write a ppm file */ - FILE *fp = fopen(file, "w"); + FILE *fp; + fp = (file) ? fopen(file, "r") : stdout; if (fp == NULL) { perror("ppm_read() Error"); @@ -20,7 +21,7 @@ ppm_write(const char *file, Image *img) fprintf(fp, "P6\n%d %d\n%d\n", img->width, img->height, img->pixel_bits); fwrite(img->data, n_pixels, sizeof(uint8_t), fp); - fclose(fp); + if (fp != stdout) fclose(fp); } void @@ -29,7 +30,8 @@ ppm_read(const char *file, Image *img) * Read a ppm file */ { - FILE *fp = fopen(file, "r"); + FILE *fp; + fp = (file) ? fopen(file, "r") : stdin; if (fp == NULL) { perror("ppm_read() Error"); @@ -50,7 +52,7 @@ ppm_read(const char *file, Image *img) fclose(fp); exit(1); } - fclose(fp); + if (fp != stdin) fclose(fp); } void -- cgit v1.2.3-70-g09d2