From 02b051634969f701ccee57505140c9e7f334e22c Mon Sep 17 00:00:00 2001 From: Laslo Hunhold Date: Wed, 11 Apr 2018 11:51:01 +0200 Subject: Add efread() and efwrite() Given we have a util.c anyway it does not make any sense to duplicate code here. This way, error handling and output is in one place and one does not have to change things in multiple different files. This also reduces code duplication by a lot. It also solves an older bug where the error reporting was not on point: $ echo "farb" | ff2png ff2png: fread: Success (It also lacked a newline) Now it properly reports $ echo "farb" | ff2png ff2png: fread: Unexpected end of file I also fixed some other minor details, for instance that all error messages should begin with a capital letter. --- ff2pam.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'ff2pam.c') diff --git a/ff2pam.c b/ff2pam.c index 9a18e6b..de96bbe 100644 --- a/ff2pam.c +++ b/ff2pam.c @@ -48,18 +48,8 @@ main(int argc, char *argv[]) width, height); for (i = 0; i < height; i++) { - if (fread(row, sizeof(uint16_t), rowlen, stdin) != rowlen) { - if (ferror(stdin)) { - fprintf(stderr, "%s: fread: %s\n", argv0, strerror(errno)); - } else { - fprintf(stderr, "%s: unexpected end of file\n", argv0); - } - return 1; - } - if (fwrite(row, sizeof(uint16_t), rowlen, stdout) != rowlen) { - fprintf(stderr, "%s: fwrite: %s\n", argv0, strerror(errno)); - return 1; - } + efread(row, sizeof(uint16_t), rowlen, stdin); + efwrite(row, sizeof(uint16_t), rowlen, stdout); } return fshut(stdout, ""); -- cgit v1.2.3