Deleted Added
full compact
example.c (237691) example.c (254069)
1/* example.c -- usage example of the zlib compression library
2 * Copyright (C) 1995-2006, 2011 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"

--- 12 unchanged lines hidden (view full) ---

21
22#define CHECK_ERR(err, msg) { \
23 if (err != Z_OK) { \
24 fprintf(stderr, "%s error: %d\n", msg, err); \
25 exit(1); \
26 } \
27}
28
1/* example.c -- usage example of the zlib compression library
2 * Copyright (C) 1995-2006, 2011 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zlib.h"

--- 12 unchanged lines hidden (view full) ---

21
22#define CHECK_ERR(err, msg) { \
23 if (err != Z_OK) { \
24 fprintf(stderr, "%s error: %d\n", msg, err); \
25 exit(1); \
26 } \
27}
28
29const char hello[] = "hello, hello!";
29z_const char hello[] = "hello, hello!";
30/* "hello world" would be more standard, but the repeated "hello"
31 * stresses the compression code better, sorry...
32 */
33
34const char dictionary[] = "hello";
35uLong dictId; /* Adler32 value of the dictionary */
36
37void test_deflate OF((Byte *compr, uLong comprLen));

--- 169 unchanged lines hidden (view full) ---

207
208 c_stream.zalloc = zalloc;
209 c_stream.zfree = zfree;
210 c_stream.opaque = (voidpf)0;
211
212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
213 CHECK_ERR(err, "deflateInit");
214
30/* "hello world" would be more standard, but the repeated "hello"
31 * stresses the compression code better, sorry...
32 */
33
34const char dictionary[] = "hello";
35uLong dictId; /* Adler32 value of the dictionary */
36
37void test_deflate OF((Byte *compr, uLong comprLen));

--- 169 unchanged lines hidden (view full) ---

207
208 c_stream.zalloc = zalloc;
209 c_stream.zfree = zfree;
210 c_stream.opaque = (voidpf)0;
211
212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
213 CHECK_ERR(err, "deflateInit");
214
215 c_stream.next_in = (Bytef*)hello;
215 c_stream.next_in = (z_const unsigned char *)hello;
216 c_stream.next_out = compr;
217
218 while (c_stream.total_in != len && c_stream.total_out < comprLen) {
219 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
220 err = deflate(&c_stream, Z_NO_FLUSH);
221 CHECK_ERR(err, "deflate");
222 }
223 /* Finish the stream, still forcing small buffers: */

--- 158 unchanged lines hidden (view full) ---

382
383 c_stream.zalloc = zalloc;
384 c_stream.zfree = zfree;
385 c_stream.opaque = (voidpf)0;
386
387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
388 CHECK_ERR(err, "deflateInit");
389
216 c_stream.next_out = compr;
217
218 while (c_stream.total_in != len && c_stream.total_out < comprLen) {
219 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
220 err = deflate(&c_stream, Z_NO_FLUSH);
221 CHECK_ERR(err, "deflate");
222 }
223 /* Finish the stream, still forcing small buffers: */

--- 158 unchanged lines hidden (view full) ---

382
383 c_stream.zalloc = zalloc;
384 c_stream.zfree = zfree;
385 c_stream.opaque = (voidpf)0;
386
387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
388 CHECK_ERR(err, "deflateInit");
389
390 c_stream.next_in = (Bytef*)hello;
390 c_stream.next_in = (z_const unsigned char *)hello;
391 c_stream.next_out = compr;
392 c_stream.avail_in = 3;
393 c_stream.avail_out = (uInt)*comprLen;
394 err = deflate(&c_stream, Z_FULL_FLUSH);
395 CHECK_ERR(err, "deflate");
396
397 compr[3]++; /* force an error in first compressed block */
398 c_stream.avail_in = len - 3;

--- 72 unchanged lines hidden (view full) ---

471 err = deflateSetDictionary(&c_stream,
472 (const Bytef*)dictionary, (int)sizeof(dictionary));
473 CHECK_ERR(err, "deflateSetDictionary");
474
475 dictId = c_stream.adler;
476 c_stream.next_out = compr;
477 c_stream.avail_out = (uInt)comprLen;
478
391 c_stream.next_out = compr;
392 c_stream.avail_in = 3;
393 c_stream.avail_out = (uInt)*comprLen;
394 err = deflate(&c_stream, Z_FULL_FLUSH);
395 CHECK_ERR(err, "deflate");
396
397 compr[3]++; /* force an error in first compressed block */
398 c_stream.avail_in = len - 3;

--- 72 unchanged lines hidden (view full) ---

471 err = deflateSetDictionary(&c_stream,
472 (const Bytef*)dictionary, (int)sizeof(dictionary));
473 CHECK_ERR(err, "deflateSetDictionary");
474
475 dictId = c_stream.adler;
476 c_stream.next_out = compr;
477 c_stream.avail_out = (uInt)comprLen;
478
479 c_stream.next_in = (Bytef*)hello;
479 c_stream.next_in = (z_const unsigned char *)hello;
480 c_stream.avail_in = (uInt)strlen(hello)+1;
481
482 err = deflate(&c_stream, Z_FINISH);
483 if (err != Z_STREAM_END) {
484 fprintf(stderr, "deflate should report Z_STREAM_END\n");
485 exit(1);
486 }
487 err = deflateEnd(&c_stream);

--- 114 unchanged lines hidden ---
480 c_stream.avail_in = (uInt)strlen(hello)+1;
481
482 err = deflate(&c_stream, Z_FINISH);
483 if (err != Z_STREAM_END) {
484 fprintf(stderr, "deflate should report Z_STREAM_END\n");
485 exit(1);
486 }
487 err = deflateEnd(&c_stream);

--- 114 unchanged lines hidden ---