diff options
author | Sangjung Woo <sangjung.woo@samsung.com> | 2016-04-06 13:14:41 +0900 |
---|---|---|
committer | Sangjung Woo <sangjung.woo@samsung.com> | 2016-04-06 17:23:33 +0900 |
commit | 8dacf5ac7708d4bd00a057011cf0b6b7c5ed945b (patch) | |
tree | 2acedfa0dba73111a3715bfc6fc88e5da35a08b2 | |
parent | 1edf9f656850c0c64dae260960fabd8249ea9c60 (diff) | |
download | bsdiff-8dacf5ac7708d4bd00a057011cf0b6b7c5ed945b.tar.gz |
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 <sangjung.woo@samsung.com>
-rw-r--r-- | bspatch.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -102,6 +102,8 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, #include <stdio.h> #include <string.h> #include <err.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <fcntl.h> @@ -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]); |