bsdiff-portable

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

commit bbd99be3efa3031b5e23f97af4039a7a6f838713
parent 02dab1e118523bae8a11531e1e1b6149954ff353
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Thu, 24 Sep 2020 16:25:17 +1000

bspatch: write newfile using stdio

Diffstat:
Mbspatch.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bspatch.c b/bspatch.c @@ -53,7 +53,7 @@ main(int argc, char **argv) FILE *f, *cpf, *dpf, *epf; BZFILE *cpfbz2, *dpfbz2, *epfbz2; int cbz2err, dbz2err, ebz2err; - int fd; + FILE *newfile; struct stat st; off_t oldsize, newsize; off_t bzctrllen, bzdatalen; @@ -83,8 +83,8 @@ main(int argc, char **argv) if ((f = fopen(argv[3], "r")) == NULL) err(1, "fopen(%s)", argv[3]); /* Open the new file */ - if ((fd = open(argv[2], O_CREAT|O_TRUNC|O_WRONLY, 0666)) == -1) - err(1, "open(%s)", argv[2]); + if ((newfile = fopen(argv[2], "w")) == NULL) + err(1, "fopen(%s)", argv[2]); #if HAVE_PLEDGE && HAVE_UNVEIL if (pledge("stdio rpath fattr", NULL) == -1) err(1, "pledge"); @@ -147,7 +147,7 @@ main(int argc, char **argv) errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); old = readfile(argv[1], &oldsize, &st); - if (fchmod(fd, st.st_mode) == -1) + if (fchmod(fileno(newfile), st.st_mode) == -1) err(1, "fchmod(%s, %04o)", argv[2], st.st_mode); #if HAVE_PLEDGE && HAVE_UNVEIL if (pledge("stdio", NULL) == -1) @@ -213,9 +213,9 @@ main(int argc, char **argv) err(1, "fclose(%s)", argv[3]); /* Write the new file */ - if (write(fd, new, newsize) != newsize) + if (fwrite(new, 1, newsize, newfile) != (size_t)newsize) err(1, "write(%s, %lld)", argv[2], (long long)newsize); - if (close(fd) == -1) + if (fclose(newfile) == -1) err(1, "close(%s)", argv[2]); free(new);