@@ -62,79 +62,79 @@ PHP_FUNCTION(bsdiff_diff)
6262 char * old_file , * new_file , * diff_file ;
6363 size_t old_file_len , new_file_len , diff_file_len ;
6464
65- ZEND_PARSE_PARAMETERS_START (3 , 3 )
65+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
6666 Z_PARAM_PATH (old_file , old_file_len )
6767 Z_PARAM_PATH (new_file , new_file_len )
6868 Z_PARAM_PATH (diff_file , diff_file_len )
69- ZEND_PARSE_PARAMETERS_END ();
70-
71- int fd ;
72- int bz2err ;
73- uint8_t * old ,* new ;
74- off_t oldsize ,newsize ;
75- uint8_t buf [8 ];
76- FILE * pf ;
77- struct bsdiff_stream stream ;
78- BZFILE * bz2 ;
79-
80- memset (& bz2 , 0 , sizeof (bz2 ));
81- stream .malloc = malloc ;
82- stream .free = free ;
83- stream .write = bz2_write ;
84-
85- /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
86- that we never try to malloc(0) and get a NULL pointer */
87- if (((fd = open (old_file ,O_RDONLY ,0 ))< 0 ) ||
88- ((oldsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
89- ((old = malloc (oldsize + 1 ))== NULL ) ||
90- (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
91- (read (fd ,old ,oldsize )!= oldsize ) ||
92- (close (fd )== -1 )) err (1 ,"%s" ,old_file );
93-
94-
95- /* Allocate newsize+1 bytes instead of newsize bytes to ensure
96- that we never try to malloc(0) and get a NULL pointer */
97- if (((fd = open (new_file ,O_RDONLY ,0 ))< 0 ) ||
98- ((newsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
99- ((new = malloc (newsize + 1 ))== NULL ) ||
100- (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
101- (read (fd ,new ,newsize )!= newsize ) ||
102- (close (fd )== -1 )) err (1 ,"%s" ,new_file );
103-
104- /* Create the patch file */
105- if ((pf = fopen (diff_file , "w" )) == NULL ) {
69+ ZEND_PARSE_PARAMETERS_END ();
70+
71+ int fd ;
72+ int bz2err ;
73+ uint8_t * old ,* new ;
74+ off_t oldsize ,newsize ;
75+ uint8_t buf [8 ];
76+ FILE * pf ;
77+ struct bsdiff_stream stream ;
78+ BZFILE * bz2 ;
79+
80+ memset (& bz2 , 0 , sizeof (bz2 ));
81+ stream .malloc = malloc ;
82+ stream .free = free ;
83+ stream .write = bz2_write ;
84+
85+ /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
86+ that we never try to malloc(0) and get a NULL pointer */
87+ if (((fd = open (old_file ,O_RDONLY ,0 ))< 0 ) ||
88+ ((oldsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
89+ ((old = malloc (oldsize + 1 ))== NULL ) ||
90+ (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
91+ (read (fd ,old ,oldsize )!= oldsize ) ||
92+ (close (fd )== -1 )) err (1 ,"%s" ,old_file );
93+
94+
95+ /* Allocate newsize+1 bytes instead of newsize bytes to ensure
96+ that we never try to malloc(0) and get a NULL pointer */
97+ if (((fd = open (new_file ,O_RDONLY ,0 ))< 0 ) ||
98+ ((newsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
99+ ((new = malloc (newsize + 1 ))== NULL ) ||
100+ (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
101+ (read (fd ,new ,newsize )!= newsize ) ||
102+ (close (fd )== -1 )) err (1 ,"%s" ,new_file );
103+
104+ /* Create the patch file */
105+ if ((pf = fopen (diff_file , "w" )) == NULL ) {
106106 err (1 , "%s" , diff_file );
107107 }
108108
109- /* Write header (signature+newsize)*/
110- offtout (newsize , buf );
111- if (fwrite ("ENDSLEY/BSDIFF43" , 16 , 1 , pf ) != 1 ||
112- fwrite (buf , sizeof (buf ), 1 , pf ) != 1 ) {
109+ /* Write header (signature+newsize)*/
110+ offtout (newsize , buf );
111+ if (fwrite ("ENDSLEY/BSDIFF43" , 16 , 1 , pf ) != 1 ||
112+ fwrite (buf , sizeof (buf ), 1 , pf ) != 1 ) {
113113 err (1 , "Failed to write header" );
114114 }
115115
116116
117- if (NULL == (bz2 = BZ2_bzWriteOpen (& bz2err , pf , 9 , 0 , 0 ))) {
117+ if (NULL == (bz2 = BZ2_bzWriteOpen (& bz2err , pf , 9 , 0 , 0 ))) {
118118 errx (1 , "BZ2_bzWriteOpen, bz2err=%d" , bz2err );
119119 }
120120
121- stream .opaque = bz2 ;
122- if (bsdiff (old , oldsize , new , newsize , & stream )) {
121+ stream .opaque = bz2 ;
122+ if (bsdiff (old , oldsize , new , newsize , & stream )) {
123123 err (1 , "bsdiff" );
124124 }
125125
126- BZ2_bzWriteClose (& bz2err , bz2 , 0 , NULL , NULL );
127- if (bz2err != BZ_OK ) {
126+ BZ2_bzWriteClose (& bz2err , bz2 , 0 , NULL , NULL );
127+ if (bz2err != BZ_OK ) {
128128 err (1 , "BZ2_bzWriteClose, bz2err=%d" , bz2err );
129129 }
130130
131- if (fclose (pf )) {
131+ if (fclose (pf )) {
132132 err (1 , "fclose" );
133133 }
134134
135- /* Free the memory we used */
136- free (old );
137- free (new );
135+ /* Free the memory we used */
136+ free (old );
137+ free (new );
138138
139139 RETURN_TRUE ;
140140}
@@ -146,78 +146,78 @@ PHP_FUNCTION(bsdiff_patch)
146146 char * old_file , * new_file , * diff_file ;
147147 size_t old_file_len , new_file_len , diff_file_len ;
148148
149- ZEND_PARSE_PARAMETERS_START (3 , 3 )
149+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
150150 Z_PARAM_PATH (old_file , old_file_len )
151151 Z_PARAM_PATH (new_file , new_file_len )
152152 Z_PARAM_PATH (diff_file , diff_file_len )
153- ZEND_PARSE_PARAMETERS_END ();
154-
155- FILE * f ;
156- int fd ;
157- int bz2err ;
158- uint8_t header [24 ];
159- uint8_t * old , * new ;
160- int64_t oldsize , newsize ;
161- BZFILE * bz2 ;
162- struct bspatch_stream stream ;
163- struct stat sb ;
164-
165- /* Open patch file */
166- if ((f = fopen (diff_file , "r" )) == NULL ) {
153+ ZEND_PARSE_PARAMETERS_END ();
154+
155+ FILE * f ;
156+ int fd ;
157+ int bz2err ;
158+ uint8_t header [24 ];
159+ uint8_t * old , * new ;
160+ int64_t oldsize , newsize ;
161+ BZFILE * bz2 ;
162+ struct bspatch_stream stream ;
163+ struct stat sb ;
164+
165+ /* Open patch file */
166+ if ((f = fopen (diff_file , "r" )) == NULL ) {
167167 err (1 , "fopen(%s)" , diff_file );
168168 }
169169
170- /* Read header */
171- if (fread (header , 1 , 24 , f ) != 24 ) {
172- if (feof (f )) {
170+ /* Read header */
171+ if (fread (header , 1 , 24 , f ) != 24 ) {
172+ if (feof (f )) {
173173 errx (1 , "Corrupt patch\n" );
174174 }
175- err (1 , "fread(%s)" , diff_file );
176- }
175+ err (1 , "fread(%s)" , diff_file );
176+ }
177177
178- /* Check for appropriate magic */
179- if (memcmp (header , "ENDSLEY/BSDIFF43" , 16 ) != 0 ) {
178+ /* Check for appropriate magic */
179+ if (memcmp (header , "ENDSLEY/BSDIFF43" , 16 ) != 0 ) {
180180 errx (1 , "Corrupt patch\n" );
181181 }
182182
183- /* Read lengths from header */
184- newsize = offtin (header + 16 );
185- if (newsize < 0 ) {
183+ /* Read lengths from header */
184+ newsize = offtin (header + 16 );
185+ if (newsize < 0 ) {
186186 errx (1 ,"Corrupt patch\n" );
187187 }
188188
189- /* Close patch file and re-open it via libbzip2 at the right places */
190- if (((fd = open (old_file ,O_RDONLY ,0 ))< 0 ) ||
191- ((oldsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
192- ((old = malloc (oldsize + 1 ))== NULL ) ||
193- (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
194- (read (fd ,old ,oldsize )!= oldsize ) ||
195- (fstat (fd , & sb )) ||
196- (close (fd )== -1 )) err (1 ,"%s" ,old_file );
197- if ((new = malloc (newsize + 1 ))== NULL ) err (1 ,NULL );
198-
199- if (NULL == (bz2 = BZ2_bzReadOpen (& bz2err , f , 0 , 0 , NULL , 0 ))) {
189+ /* Close patch file and re-open it via libbzip2 at the right places */
190+ if (((fd = open (old_file ,O_RDONLY ,0 ))< 0 ) ||
191+ ((oldsize = lseek (fd ,0 ,SEEK_END ))== -1 ) ||
192+ ((old = malloc (oldsize + 1 ))== NULL ) ||
193+ (lseek (fd ,0 ,SEEK_SET )!= 0 ) ||
194+ (read (fd ,old ,oldsize )!= oldsize ) ||
195+ (fstat (fd , & sb )) ||
196+ (close (fd )== -1 )) err (1 ,"%s" ,old_file );
197+ if ((new = malloc (newsize + 1 ))== NULL ) err (1 ,NULL );
198+
199+ if (NULL == (bz2 = BZ2_bzReadOpen (& bz2err , f , 0 , 0 , NULL , 0 ))) {
200200 errx (1 , "BZ2_bzReadOpen, bz2err=%d" , bz2err );
201201 }
202202
203- stream .read = bz2_read ;
204- stream .opaque = bz2 ;
205- if (bspatch (old , oldsize , new , newsize , & stream )) {
203+ stream .read = bz2_read ;
204+ stream .opaque = bz2 ;
205+ if (bspatch (old , oldsize , new , newsize , & stream )) {
206206 errx (1 , "bspatch" );
207207 }
208208
209- /* Clean up the bzip2 reads */
210- BZ2_bzReadClose (& bz2err , bz2 );
211- fclose (f );
209+ /* Clean up the bzip2 reads */
210+ BZ2_bzReadClose (& bz2err , bz2 );
211+ fclose (f );
212212
213- /* Write the new file */
214- if (((fd = open (new_file ,O_CREAT |O_TRUNC |O_WRONLY ,sb .st_mode ))< 0 ) ||
215- (write (fd ,new ,newsize )!= newsize ) || (close (fd )== -1 )) {
213+ /* Write the new file */
214+ if (((fd = open (new_file ,O_CREAT |O_TRUNC |O_WRONLY ,sb .st_mode ))< 0 ) ||
215+ (write (fd ,new ,newsize )!= newsize ) || (close (fd )== -1 )) {
216216 err (1 ,"%s" ,new_file );
217217 }
218218
219- free (new );
220- free (old );
219+ free (new );
220+ free (old );
221221
222222 RETURN_TRUE ;
223223}
@@ -227,10 +227,10 @@ PHP_FUNCTION(bsdiff_patch)
227227PHP_RINIT_FUNCTION (bsdiff )
228228{
229229#if defined(ZTS ) && defined(COMPILE_DL_BSDIFF )
230- ZEND_TSRMLS_CACHE_UPDATE ();
230+ ZEND_TSRMLS_CACHE_UPDATE ();
231231#endif
232232
233- return SUCCESS ;
233+ return SUCCESS ;
234234}
235235/* }}} */
236236
@@ -246,24 +246,24 @@ PHP_MINIT_FUNCTION(bsdiff)
246246/* {{{ PHP_MINFO_FUNCTION */
247247PHP_MINFO_FUNCTION (bsdiff )
248248{
249- php_info_print_table_start ();
250- php_info_print_table_header (2 , "bsdiff support" , "enabled" );
251- php_info_print_table_end ();
249+ php_info_print_table_start ();
250+ php_info_print_table_header (2 , "bsdiff support" , "enabled" );
251+ php_info_print_table_end ();
252252}
253253/* }}} */
254254
255255/* {{{ bsdiff_module_entry */
256256zend_module_entry bsdiff_module_entry = {
257- STANDARD_MODULE_HEADER ,
258- "bsdiff" , /* Extension name */
259- ext_functions , /* zend_function_entry */
257+ STANDARD_MODULE_HEADER ,
258+ "bsdiff" , /* Extension name */
259+ ext_functions , /* zend_function_entry */
260260 PHP_MINIT (bsdiff ), /* PHP_MINIT - Module initialization */
261- NULL , /* PHP_MSHUTDOWN - Module shutdown */
261+ NULL , /* PHP_MSHUTDOWN - Module shutdown */
262262 PHP_RINIT (bsdiff ), /* PHP_RINIT - Request initialization */
263- NULL , /* PHP_RSHUTDOWN - Request shutdown */
264- PHP_MINFO (bsdiff ), /* PHP_MINFO - Module info */
265- PHP_BSDIFF_VERSION , /* Version */
266- STANDARD_MODULE_PROPERTIES
263+ NULL , /* PHP_RSHUTDOWN - Request shutdown */
264+ PHP_MINFO (bsdiff ), /* PHP_MINFO - Module info */
265+ PHP_BSDIFF_VERSION , /* Version */
266+ STANDARD_MODULE_PROPERTIES
267267};
268268/* }}} */
269269
0 commit comments