From owner-p4-projects@FreeBSD.ORG Wed Sep 10 15:24:18 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E7A8B10656FC; Wed, 10 Sep 2008 15:24:17 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDA5E106567B for ; Wed, 10 Sep 2008 15:24:16 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A98468FC1B for ; Wed, 10 Sep 2008 15:24:16 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m8AFOGwE055638 for ; Wed, 10 Sep 2008 15:24:16 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m8AFOGk0055636 for perforce@freebsd.org; Wed, 10 Sep 2008 15:24:16 GMT (envelope-from strauss@FreeBSD.org) Date: Wed, 10 Sep 2008 15:24:16 GMT Message-Id: <200809101524.m8AFOGk0055636@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 149533 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Sep 2008 15:24:18 -0000 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 -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 #include -#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); }