@@ -102,6 +102,8 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize,
102
102
#include <stdio.h>
103
103
#include <string.h>
104
104
#include <err.h>
105
+ #include <sys/types.h>
106
+ #include <sys/stat.h>
105
107
#include <unistd.h>
106
108
#include <fcntl.h>
107
109
@@ -129,6 +131,7 @@ int main(int argc,char * argv[])
129
131
int64_t oldsize , newsize ;
130
132
BZFILE * bz2 ;
131
133
struct bspatch_stream stream ;
134
+ struct stat sb ;
132
135
133
136
if (argc != 4 ) errx (1 ,"usage: %s oldfile newfile patchfile\n" ,argv [0 ]);
134
137
@@ -158,6 +161,7 @@ int main(int argc,char * argv[])
158
161
((old = malloc (oldsize + 1 ))== NULL ) ||
159
162
(lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
160
163
(read (fd ,old ,oldsize )!= oldsize ) ||
164
+ (fstat (fd , & sb )) ||
161
165
(close (fd )== -1 )) err (1 ,"%s" ,argv [1 ]);
162
166
if ((new = malloc (newsize + 1 ))== NULL ) err (1 ,NULL );
163
167
@@ -174,7 +178,7 @@ int main(int argc,char * argv[])
174
178
fclose (f );
175
179
176
180
/* 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 ) ||
178
182
(write (fd ,new ,newsize )!= newsize ) || (close (fd )== -1 ))
179
183
err (1 ,"%s" ,argv [2 ]);
180
184
0 commit comments