diff options
-rw-r--r-- | ff2jpg.c | 2 | ||||
-rw-r--r-- | ff2pam.c | 2 | ||||
-rw-r--r-- | ff2png.c | 2 | ||||
-rw-r--r-- | ff2ppm.c | 2 | ||||
-rw-r--r-- | jpg2ff.c | 2 | ||||
-rw-r--r-- | png2ff.c | 2 | ||||
-rw-r--r-- | util.c | 27 | ||||
-rw-r--r-- | util.h | 2 |
8 files changed, 35 insertions, 6 deletions
@@ -118,5 +118,5 @@ main(int argc, char *argv[]) jpeg_finish_compress(&jcomp); jpeg_destroy_compress(&jcomp); - return 0; + return fshut(stdout, "<stdout>"); } @@ -62,5 +62,5 @@ main(int argc, char *argv[]) } } - return 0; + return fshut(stdout, "<stdout>"); } @@ -83,5 +83,5 @@ main(int argc, char *argv[]) png_write_end(pngs, NULL); png_destroy_write_struct(&pngs, NULL); - return 0; + return fshut(stdout, "<stdout>"); } @@ -77,5 +77,5 @@ main(int argc, char *argv[]) } } - return 0; + return fshut(stdout, "<stdout>"); } @@ -90,5 +90,5 @@ main(int argc, char *argv[]) jpeg_finish_decompress(&js); jpeg_destroy_decompress(&js); - return 0; + return fshut(stdout, "<stdout>"); } @@ -107,5 +107,5 @@ main(int argc, char *argv[]) /* clean up */ png_destroy_read_struct(&pngs, &pngi, NULL); - return 0; + return fshut(stdout, "<stdout>"); } @@ -82,6 +82,33 @@ parse_mask(const char *s, uint16_t mask[3]) return 0; } +int +fshut(FILE *fp, const char *fname) +{ + int ret = 0; + + /* fflush() is undefined for input streams by ISO C, + * but not POSIX 2008 if you ignore ISO C overrides. + * Leave it unchecked and rely on the following + * functions to detect errors. + */ + fflush(fp); + + if (ferror(fp) && !ret) { + fprintf(stderr, "%s: ferror %s: %s\n", argv0, fname, + strerror(errno)); + ret = 1; + } + + if (fclose(fp) && !ret) { + fprintf(stderr, "%s: fclose %s: %s\n", argv0, fname, + strerror(errno)); + ret = 1; + } + + return ret; +} + void * ereallocarray(void *optr, size_t nmemb, size_t size) { @@ -11,6 +11,8 @@ void ff_write_header(uint32_t width, uint32_t height); int parse_mask(const char *, uint16_t mask[3]); +int fshut(FILE *, const char *); + #undef reallocarray void *reallocarray(void *, size_t, size_t); void *ereallocarray(void *optr, size_t nmemb, size_t size); |