Skip to content

Commit 7d70d8f

Browse files
authored
Merge pull request #11 from again4you/devel/fix_permission
Use the same access mode of original file instead of fixed value
2 parents 1edf9f6 + 8dacf5a commit 7d70d8f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bspatch.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize,
102102
#include <stdio.h>
103103
#include <string.h>
104104
#include <err.h>
105+
#include <sys/types.h>
106+
#include <sys/stat.h>
105107
#include <unistd.h>
106108
#include <fcntl.h>
107109

@@ -129,6 +131,7 @@ int main(int argc,char * argv[])
129131
int64_t oldsize, newsize;
130132
BZFILE* bz2;
131133
struct bspatch_stream stream;
134+
struct stat sb;
132135

133136
if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
134137

@@ -158,6 +161,7 @@ int main(int argc,char * argv[])
158161
((old=malloc(oldsize+1))==NULL) ||
159162
(lseek(fd,0,SEEK_SET)!=0) ||
160163
(read(fd,old,oldsize)!=oldsize) ||
164+
(fstat(fd, &sb)) ||
161165
(close(fd)==-1)) err(1,"%s",argv[1]);
162166
if((new=malloc(newsize+1))==NULL) err(1,NULL);
163167

@@ -174,7 +178,7 @@ int main(int argc,char * argv[])
174178
fclose(f);
175179

176180
/* Write the new file */
177-
if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) ||
181+
if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,sb.st_mode))<0) ||
178182
(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
179183
err(1,"%s",argv[2]);
180184

0 commit comments

Comments
 (0)