summaryrefslogtreecommitdiff
path: root/usr.bin/bsdiff
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2006-12-05 20:22:14 +0000
committerColin Percival <cperciva@FreeBSD.org>2006-12-05 20:22:14 +0000
commit8904d5ecb17e4411a521d0f4f399e5b260179bfc (patch)
tree8683c7f9b9ed80ec6eca21f41b99b91554ee3e4d /usr.bin/bsdiff
parent61e5d30af7c74f1541d60ee0da08ae6ac8f49ed4 (diff)
downloadsrc-test-8904d5ecb17e4411a521d0f4f399e5b260179bfc.tar.gz
src-test-8904d5ecb17e4411a521d0f4f399e5b260179bfc.zip
Portability fix for non-POSIX operating systems: Open files in binary mode.
PR: bin/106358 Submitted by: techtonik at php dot net
Notes
Notes: svn path=/head/; revision=164922
Diffstat (limited to 'usr.bin/bsdiff')
-rw-r--r--usr.bin/bsdiff/bsdiff/bsdiff.c10
-rw-r--r--usr.bin/bsdiff/bspatch/bspatch.c16
2 files changed, 17 insertions, 9 deletions
diff --git a/usr.bin/bsdiff/bsdiff/bsdiff.c b/usr.bin/bsdiff/bsdiff/bsdiff.c
index df9a0580831ea..005ad4d16610a 100644
--- a/usr.bin/bsdiff/bsdiff/bsdiff.c
+++ b/usr.bin/bsdiff/bsdiff/bsdiff.c
@@ -37,6 +37,10 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#define MIN(x,y) (((x)<(y)) ? (x) : (y))
static void split(off_t *I,off_t *V,off_t start,off_t len,off_t h)
@@ -216,7 +220,7 @@ int main(int argc,char *argv[])
/* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
that we never try to malloc(0) and get a NULL pointer */
- if(((fd=open(argv[1],O_RDONLY,0))<0) ||
+ if(((fd=open(argv[1],O_RDONLY|O_BINARY,0))<0) ||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
@@ -232,7 +236,7 @@ int main(int argc,char *argv[])
/* Allocate newsize+1 bytes instead of newsize bytes to ensure
that we never try to malloc(0) and get a NULL pointer */
- if(((fd=open(argv[2],O_RDONLY,0))<0) ||
+ if(((fd=open(argv[2],O_RDONLY|O_BINARY,0))<0) ||
((newsize=lseek(fd,0,SEEK_END))==-1) ||
((new=malloc(newsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
@@ -245,7 +249,7 @@ int main(int argc,char *argv[])
eblen=0;
/* Create the patch file */
- if ((pf = fopen(argv[3], "w")) == NULL)
+ if ((pf = fopen(argv[3], "wb")) == NULL)
err(1, "%s", argv[3]);
/* Header is
diff --git a/usr.bin/bsdiff/bspatch/bspatch.c b/usr.bin/bsdiff/bspatch/bspatch.c
index bf6baa91d18d3..d2af3ca869a26 100644
--- a/usr.bin/bsdiff/bspatch/bspatch.c
+++ b/usr.bin/bsdiff/bspatch/bspatch.c
@@ -35,6 +35,10 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include <fcntl.h>
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
static off_t offtin(u_char *buf)
{
off_t y;
@@ -71,7 +75,7 @@ int main(int argc,char * argv[])
if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
/* Open patch file */
- if ((f = fopen(argv[3], "r")) == NULL)
+ if ((f = fopen(argv[3], "rb")) == NULL)
err(1, "fopen(%s)", argv[3]);
/*
@@ -109,21 +113,21 @@ int main(int argc,char * argv[])
/* Close patch file and re-open it via libbzip2 at the right places */
if (fclose(f))
err(1, "fclose(%s)", argv[3]);
- if ((cpf = fopen(argv[3], "r")) == NULL)
+ if ((cpf = fopen(argv[3], "rb")) == NULL)
err(1, "fopen(%s)", argv[3]);
if (fseeko(cpf, 32, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
(long long)32);
if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
- if ((dpf = fopen(argv[3], "r")) == NULL)
+ if ((dpf = fopen(argv[3], "rb")) == NULL)
err(1, "fopen(%s)", argv[3]);
if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
(long long)(32 + bzctrllen));
if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
- if ((epf = fopen(argv[3], "r")) == NULL)
+ if ((epf = fopen(argv[3], "rb")) == NULL)
err(1, "fopen(%s)", argv[3]);
if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
@@ -131,7 +135,7 @@ int main(int argc,char * argv[])
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
- if(((fd=open(argv[1],O_RDONLY,0))<0) ||
+ if(((fd=open(argv[1],O_RDONLY|O_BINARY,0))<0) ||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
@@ -192,7 +196,7 @@ int 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) ||
+ if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))<0) ||
(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
err(1,"%s",argv[2]);