RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Anders F. Björklund
Root: /v/rpm/cvs Email: afb@rpm5.org
Module: xar Date: 20-Sep-2007 12:29:14
Branch: HEAD Handle: 2007092011291300
Modified files:
xar/lib bzxar.c zxar.c
Log:
code cleanup
Summary:
Revision Changes Path
1.4 +21 -21 xar/lib/bzxar.c
1.4 +27 -28 xar/lib/zxar.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: xar/lib/bzxar.c
============================================================================
$ cvs diff -u -r1.3 -r1.4 bzxar.c
--- xar/lib/bzxar.c 19 Sep 2007 22:14:01 -0000 1.3
+++ xar/lib/bzxar.c 20 Sep 2007 10:29:13 -0000 1.4
@@ -62,7 +62,23 @@
#define BZIP2_CONTEXT(x) ((struct _bzip_context *)(*x))
#endif
-int xar_bzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context);
+int xar_bzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
+#ifdef HAVE_LIBBZ2
+
+ if( !context || !BZIP2_CONTEXT(context) )
+ return 0;
+
+ if( BZIP2_CONTEXT(context)->bzipcompressed){
+ BZ2_bzDecompressEnd(&BZIP2_CONTEXT(context)->bz);
+ }
+
+ /* free the context */
+ free(BZIP2_CONTEXT(context));
+ *context = NULL;
+
+#endif /* HAVE_LIBBZ2 */
+ return 0;
+}
int xar_bzip_fromheap_in(xar_t x, xar_file_t f, xar_prop_t p, void **in, size_t *inlen, void **context) {
#ifdef HAVE_LIBBZ2
@@ -89,8 +105,8 @@
return 0;
}else if( !(BZIP2_CONTEXT(context)->bzipcompressed) ){
/* once the context has been initialized, then we have already
- checked the compression type, so we need only check if we
- actually are compressed */
+ checked the compression type, so we need only check if we
+ actually are compressed */
return 0;
}
@@ -129,23 +145,6 @@
return 0;
}
-int xar_bzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
-#ifdef HAVE_LIBBZ2
-
- if( !context || !BZIP2_CONTEXT(context) )
- return 0;
-
- if( BZIP2_CONTEXT(context)->bzipcompressed){
- BZ2_bzDecompressEnd(&BZIP2_CONTEXT(context)->bz);
- }
-
- free(BZIP2_CONTEXT(context));
- *context = NULL;
-
-#endif /* HAVE_LIBBZ2 */
- return 0;
-}
-
int xar_bzip_toheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
#ifdef HAVE_LIBBZ2
xar_prop_t tmpp;
@@ -158,6 +157,7 @@
xar_attr_pset(f, tmpp, "style", "application/x-bzip2");
}
+ /* free the context */
free(BZIP2_CONTEXT(context));
*context = NULL;
@@ -207,7 +207,7 @@
BZIP2_CONTEXT(context)->bz.next_out = ((char *)out) + offset;
BZIP2_CONTEXT(context)->bz.avail_out = outlen - offset;
- if( (*inlen == 0) )
+ if( *inlen == 0 )
r = BZ2_bzCompress(&BZIP2_CONTEXT(context)->bz, BZ_FINISH);
else
r = BZ2_bzCompress(&BZIP2_CONTEXT(context)->bz, BZ_RUN);
@@ .
patch -p0 <<'@@ .'
Index: xar/lib/zxar.c
============================================================================
$ cvs diff -u -r1.3 -r1.4 zxar.c
--- xar/lib/zxar.c 19 Sep 2007 22:14:01 -0000 1.3
+++ xar/lib/zxar.c 20 Sep 2007 10:29:13 -0000 1.4
@@ -35,28 +35,43 @@
* Christopher Ryan <ryanc@apple.com>
*/
+
+#include "config.h"
+#ifndef HAVE_ASPRINTF
+#include "asprintf.h"
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <zlib.h>
-#include "config.h"
-#ifndef HAVE_ASPRINTF
-#include "asprintf.h"
-#endif
#include "xar.h"
#include "filetree.h"
#include "io.h"
-typedef struct _gzip_context{
+struct _gzip_context{
uint8_t gzipcompressed;
uint64_t count;
z_stream z;
-} gzip_context;
+};
#define GZIP_CONTEXT(x) ((struct _gzip_context *)(*x))
-int xar_gzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context);
+int xar_gzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
+
+ if( !context || !GZIP_CONTEXT(context) )
+ return 0;
+
+ if( GZIP_CONTEXT(context)->gzipcompressed){
+ inflateEnd(&GZIP_CONTEXT(context)->z);
+ }
+
+ /* free the context */
+ free(GZIP_CONTEXT(context));
+ *context = NULL;
+
+ return 0;
+}
int xar_gzip_fromheap_in(xar_t x, xar_file_t f, xar_prop_t p, void **in, size_t *inlen, void **context) {
const char *opt;
@@ -64,11 +79,11 @@
size_t outlen, offset = 0;
int r;
xar_prop_t tmpp;
-
+
/* on first run, we init the context and check the compression type */
if( !GZIP_CONTEXT(context) ) {
*context = calloc(1,sizeof(struct _gzip_context));
-
+
opt = NULL;
tmpp = xar_prop_pget(p, "encoding");
if( tmpp )
@@ -76,15 +91,14 @@
if( !opt ) return 0;
if( strcmp(opt, "application/x-gzip") != 0 ) return 0;
- GZIP_CONTEXT(context)->gzipcompressed = 1;
inflateInit(&GZIP_CONTEXT(context)->z);
+ GZIP_CONTEXT(context)->gzipcompressed = 1;
}else if( !GZIP_CONTEXT(context)->gzipcompressed ){
/* once the context has been initialized, then we have already
checked the compression type, so we need only check if we
actually are compressed */
return 0;
}
-
outlen = *inlen;
@@ -120,21 +134,6 @@
return 0;
}
-int xar_gzip_fromheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
-
- if( !context || !GZIP_CONTEXT(context) )
- return 0;
-
- if( GZIP_CONTEXT(context)->gzipcompressed){
- inflateEnd(&GZIP_CONTEXT(context)->z);
- }
-
- /* free the context */
- free(GZIP_CONTEXT(context));
- *context = NULL;
-
- return 0;
-}
int xar_gzip_toheap_done(xar_t x, xar_file_t f, xar_prop_t p, void **context) {
xar_prop_t tmpp;
@@ -172,8 +171,8 @@
if( strcmp(opt, XAR_OPT_VAL_GZIP) != 0 )
return 0;
- GZIP_CONTEXT(context)->gzipcompressed = 1;
deflateInit(&GZIP_CONTEXT(context)->z, Z_BEST_COMPRESSION);
+ GZIP_CONTEXT(context)->gzipcompressed = 1;
if( *inlen == 0 )
return 0;
}else if( !GZIP_CONTEXT(context)->gzipcompressed ){
@@ -182,7 +181,7 @@
actually are compressed */
return 0;
}
-
+
outlen = *inlen/2;
if(outlen == 0) outlen = 1024;
GZIP_CONTEXT(context)->z.next_in = *in;
@@ .
Received on Thu Sep 20 12:29:14 2007