bsdiff-portable

A more portable version of Colin Percival's bsdiff
git clone git://git.sgregoratto.me/bsdiff-portable
Log | Files | Refs | LICENSE

commit 7661cd30aa1c94db598b4361f97a43a3be1729ce
parent 3057fab5a8fde64f0058ef42c072925ff014f13d
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Wed, 23 Sep 2020 21:00:42 +1000

make error reporting consistent

Diffstat:
Mbsdiff.c | 6+++---
Mbspatch.c | 15+++++++++------
2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/bsdiff.c b/bsdiff.c @@ -86,7 +86,7 @@ main(int argc, char **argv) /* Create the patch file */ if ((pf = fopen(argv[3], "w")) == NULL) - err(1, "%s", argv[3]); + err(1, "fopen(%s)", argv[3]); /* Header is 0 8 "BSDIFF40" @@ -102,8 +102,8 @@ main(int argc, char **argv) offtout(0, header + 8); offtout(0, header + 16); offtout(newsize, header + 24); - if (fwrite(header, 32, 1, pf) != 1) - err(1, "fwrite(%s)", argv[3]); + if (fwrite(header, 32, 1, pf) == 0) + err(1, "fwrite(%s, %lld)", argv[3], (long long)32); /* Compute the differences, writing ctrl as we go */ if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL) diff --git a/bspatch.c b/bspatch.c @@ -160,18 +160,18 @@ main(int argc, char **argv) /* Sanity-check */ if (newpos + ctrl[1] > newsize) - errx(1, "Corrupt patch\n"); + errx(1, "Corrupt patch"); /* Read extra string */ lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); if ((lenread < ctrl[1]) || ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) - errx(1, "Corrupt patch\n"); + errx(1, "Corrupt patch"); /* Adjust pointers */ newpos += ctrl[1]; oldpos += ctrl[2]; - }; + } /* Clean up the bzip2 reads */ BZ2_bzReadClose(&cbz2err, cpfbz2); @@ -181,9 +181,12 @@ main(int argc, char **argv) err(1, "fclose(%s)", argv[3]); /* Write the new file */ - if (((fd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) || - (write(fd, new, newsize) != newsize) || (close(fd) == -1)) - err(1, "%s", argv[2]); + if ((fd = open(argv[2], O_CREAT|O_TRUNC|O_WRONLY, 0666)) == -1) + err(1, "open(%s)", argv[2]); + if (write(fd, new, newsize) != newsize) + err(1, "write(%s, %lld)", argv[2], (long long)newsize); + if (close(fd) == -1) + err(1, "close(%s)", argv[2]); free(new); free(old);