diff options
Diffstat (limited to 'src/ppm.c')
-rw-r--r-- | src/ppm.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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 |