Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Sep 2008 15:24:16 GMT
From:      Anselm Strauss <strauss@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 149533 for review
Message-ID:  <200809101524.m8AFOGk0055636@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=149533

Change 149533 by strauss@strauss_marvelman on 2008/09/10 15:23:29

	Fixed deflate example, now applying to ZIP writer ...

Affected files ...

.. //depot/projects/soc2008/strauss_libarchive/misc/deflate/common.c#2 edit
.. //depot/projects/soc2008/strauss_libarchive/misc/deflate/common.h#3 edit
.. //depot/projects/soc2008/strauss_libarchive/misc/deflate/deflate.c#3 edit
.. //depot/projects/soc2008/strauss_libarchive/misc/deflate/inflate.c#2 edit
.. //depot/projects/soc2008/strauss_libarchive/misc/deflate/test.sh#1 add

Differences ...

==== //depot/projects/soc2008/strauss_libarchive/misc/deflate/common.c#2 (text+ko) ====

@@ -1,13 +1,18 @@
 #include "common.h"
+#include <stdarg.h>
 
-void err_msg(const char *string) {
-  fputs("Error: ", stderr);
-  fputs(string, stderr);
+void err_msg(const char *string, ...) {
+  va_list args;
+  va_start(args, string);
+  fputs("error: ", stderr);
+  vfprintf(stderr, string, args);
   fputs("\n", stderr);
 }
 
-void debug_msg(const char *string) {
-  fputs("Debug: ", stderr);
-  fputs(string, stderr);
+void debug_msg(const char *string, ...) {
+  va_list args;
+  va_start(args, string);
+  fputs("debug: ", stderr);
+  vfprintf(stderr, string, args);
   fputs("\n", stderr);
 }

==== //depot/projects/soc2008/strauss_libarchive/misc/deflate/common.h#3 (text+ko) ====

@@ -1,14 +1,14 @@
 #include <stdio.h>
 #include <zlib.h>
 
-#define CHUNK 8
+#define CHUNK 1024
 
-//#define DEBUG
+#define DEBUG
 #ifdef DEBUG
-  #define debug(s) debug_msg(s);
+  #define debug(...) debug_msg(__VA_ARGS__);
 #else
-  #define debug(s)
+  #define debug(...)
 #endif
 
-void err_msg(const char *);
-void debug_msg(const char *);
+void err_msg(const char *, ...);
+void debug_msg(const char *, ...);

==== //depot/projects/soc2008/strauss_libarchive/misc/deflate/deflate.c#3 (text+ko) ====

@@ -7,6 +7,7 @@
   int flush;
   int ret;
   int eof;
+  unsigned int deflated;
 
   stream.zalloc = Z_NULL;
   stream.zfree = Z_NULL;
@@ -21,7 +22,7 @@
       err_msg("while reading from standard input");
       return 1;
     }
-    debug("read from stdin");
+    debug("read %u units from stdin", stream.avail_in);
     eof = feof(stdin);
     flush = eof ? Z_FINISH : Z_NO_FLUSH;
     do {
@@ -33,14 +34,15 @@
 	err_msg("while deflating");
 	return 1;
       }
-      debug("deflated data");
-      ret = fwrite(out, 1, stream.avail_out, stdout);
-      if ( ret != stream.avail_out || ferror(stdout)) {
+      deflated = CHUNK - stream.avail_out;
+      debug("deflated %u units", deflated);
+      ret = fwrite(out, 1, deflated, stdout);
+      if ( ret != deflated || ferror(stdout)) {
         deflateEnd(&stream);
 	err_msg("while writing to standard output");
 	return 1;
       };
-      debug("wrote to stdout");
+      debug("wrote %i units to stdout", ret);
     } while (stream.avail_out == 0);
   } while (!eof);
 }

==== //depot/projects/soc2008/strauss_libarchive/misc/deflate/inflate.c#2 (text+ko) ====

@@ -7,6 +7,7 @@
   int flush;
   int ret;
   int eof;
+  unsigned int inflated;
 
   stream.zalloc = Z_NULL;
   stream.zfree = Z_NULL;
@@ -21,7 +22,7 @@
       err_msg("while reading from standard input");
       return 1;
     }
-    debug("read from stdin");
+    debug("read %u units from stdin", stream.avail_in);
     eof = feof(stdin);
     flush = eof ? Z_FINISH : Z_NO_FLUSH;
     do {
@@ -33,14 +34,15 @@
 	err_msg("while inflating");
 	return 1;
       }
-      debug("inflated data");
-      ret = fwrite(out, 1, stream.avail_out, stdout);
-      if ( ret != stream.avail_out || ferror(stdout)) {
+      inflated = CHUNK - stream.avail_out;
+      debug("inflated %u units", inflated);
+      ret = fwrite(out, 1, inflated, stdout);
+      if ( ret != inflated || ferror(stdout)) {
         inflateEnd(&stream);
 	err_msg("while writing to standard output");
 	return 1;
       };
-      debug("wrote to stdout");
+      debug("wrote %i units to stdout", ret);
     } while (stream.avail_out == 0);
   } while (!eof);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809101524.m8AFOGk0055636>