summaryrefslogtreecommitdiff
path: root/ff2pam.c
diff options
context:
space:
mode:
authorLaslo Hunhold <dev@frign.de>2018-04-11 11:51:01 +0200
committerLaslo Hunhold <dev@frign.de>2018-04-11 11:51:01 +0200
commit02b051634969f701ccee57505140c9e7f334e22c (patch)
tree5fe33152959cbe29996754dee7529ccc07bf9440 /ff2pam.c
parenta9877de22960f14fb16e862cf46290a477779e98 (diff)
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.
Diffstat (limited to 'ff2pam.c')
-rw-r--r--ff2pam.c14
1 files changed, 2 insertions, 12 deletions
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, "<stdout>");