From 8dacf5ac7708d4bd00a057011cf0b6b7c5ed945b Mon Sep 17 00:00:00 2001 From: Sangjung Woo Date: Wed, 6 Apr 2016 13:14:41 +0900 Subject: bspatch: Use the same access mode of original file instead of fixed value. After running the bspatch, the created file always has fixed access mode value (i.e. 0666) since this command does not consider the access mode. This patch uses the same access mode of the original file. Signed-off-by: Sangjung Woo --- bspatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bspatch.c b/bspatch.c index 881d7e3..b544914 100644 --- a/bspatch.c +++ b/bspatch.c @@ -102,6 +102,8 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, #include #include #include +#include +#include #include #include @@ -129,6 +131,7 @@ int main(int argc,char * argv[]) int64_t oldsize, newsize; BZFILE* bz2; struct bspatch_stream stream; + struct stat sb; if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); @@ -158,6 +161,7 @@ int main(int argc,char * argv[]) ((old=malloc(oldsize+1))==NULL) || (lseek(fd,0,SEEK_SET)!=0) || (read(fd,old,oldsize)!=oldsize) || + (fstat(fd, &sb)) || (close(fd)==-1)) err(1,"%s",argv[1]); if((new=malloc(newsize+1))==NULL) err(1,NULL); @@ -174,7 +178,7 @@ int main(int argc,char * argv[]) fclose(f); /* 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,sb.st_mode))<0) || (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) err(1,"%s",argv[2]); -- cgit v1.2.1