Changeset f1c8de9 in rtems for cpukit/zlib


Ignore:
Timestamp:
Mar 18, 2011, 10:11:00 AM (9 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.11, master
Children:
ebe2800
Parents:
3a0d65c0
Message:

Import from zlib-1.2.4

Location:
cpukit/zlib/examples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/zlib/examples/zlib_how.html

    r3a0d65c0 rf1c8de9  
    55<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    66<title>zlib Usage Example</title>
    7 <!--  Copyright (c) 2004 Mark Adler.  -->
     7<!--  Copyright (c) 2004, 2005 Mark Adler.  -->
    88</head>
    99<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000">
     
    2222/* zpipe.c: example of proper use of zlib's inflate() and deflate()
    2323   Not copyrighted -- provided to the public domain
    24    Version 1.2  9 November 2004  Mark Adler */
     24   Version 1.4  11 December 2005  Mark Adler */
    2525
    2626/* Version history:
     
    2929                     Use switch statement for inflate() return values
    3030   1.2   9 Nov 2004  Add assertions to document zlib guarantees
     31   1.3   6 Apr 2005  Remove incorrect assertion in inf()
     32   1.4  11 Dec 2005  Add hack to avoid MSDOS end-of-line conversions
     33                     Avoid some compiler warnings for input and output buffers
    3134 */
    3235</b></pre><!-- -->
     
    4851#include "zlib.h"
    4952</b></pre><!-- -->
     53This is an ugly hack required to avoid corruption of the input and output data on
     54Windows/MS-DOS systems.  Without this, those systems would assume that the input and output
     55files are text, and try to convert the end-of-line characters from one standard to
     56another.  That would corrupt binary data, and in particular would render the compressed data unusable.
     57This sets the input and output to binary which suppresses the end-of-line conversions.
     58<tt>SET_BINARY_MODE()</tt> will be used later on <tt>stdin</tt> and <tt>stdout</tt>, at the beginning of <tt>main()</tt>.
     59<pre><b>
     60#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
     61#  include &lt;fcntl.h&gt;
     62#  include &lt;io.h&gt;
     63#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
     64#else
     65#  define SET_BINARY_MODE(file)
     66#endif
     67</b></pre><!-- -->
    5068<tt>CHUNK</tt> is simply the buffer size for feeding data to and pulling data
    5169from the <em>zlib</em> routines.  Larger buffer sizes would be more efficient,
     
    8199    unsigned have;
    82100    z_stream strm;
    83     char in[CHUNK];
    84     char out[CHUNK];
     101    unsigned char in[CHUNK];
     102    unsigned char out[CHUNK];
    85103</b></pre><!-- -->
    86104The first thing we do is to initialize the <em>zlib</em> state for compression using
     
    314332    unsigned have;
    315333    z_stream strm;
    316     char in[CHUNK];
    317     char out[CHUNK];
     334    unsigned char in[CHUNK];
     335    unsigned char out[CHUNK];
    318336</b></pre><!-- -->
    319337The initialization of the state is the same, except that there is no compression level,
     
    495513    int ret;
    496514
     515    /* avoid end-of-line conversions */
     516    SET_BINARY_MODE(stdin);
     517    SET_BINARY_MODE(stdout);
     518
    497519    /* do compression if no arguments */
    498520    if (argc == 1) {
     
    519541</b></pre>
    520542<hr>
    521 <i>Copyright (c) 2004 by Mark Adler<br>Last modified 13 November 2004</i>
     543<i>Copyright (c) 2004, 2005 by Mark Adler<br>Last modified 11 December 2005</i>
    522544</body>
    523545</html>
  • cpukit/zlib/examples/zpipe.c

    r3a0d65c0 rf1c8de9  
    11/* zpipe.c: example of proper use of zlib's inflate() and deflate()
    22   Not copyrighted -- provided to the public domain
    3    Version 1.2  9 November 2004  Mark Adler */
     3   Version 1.4  11 December 2005  Mark Adler */
    44
    55/* Version history:
     
    99   1.2   9 Nov 2004  Add assertions to document zlib guarantees
    1010   1.3   6 Apr 2005  Remove incorrect assertion in inf()
     11   1.4  11 Dec 2005  Add hack to avoid MSDOS end-of-line conversions
     12                     Avoid some compiler warnings for input and output buffers
    1113 */
    1214
     
    1517#include <assert.h>
    1618#include "zlib.h"
     19
     20#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
     21#  include <fcntl.h>
     22#  include <io.h>
     23#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
     24#else
     25#  define SET_BINARY_MODE(file)
     26#endif
    1727
    1828#define CHUNK 16384
     
    2939    unsigned have;
    3040    z_stream strm;
    31     char in[CHUNK];
    32     char out[CHUNK];
     41    unsigned char in[CHUNK];
     42    unsigned char out[CHUNK];
    3343
    3444    /* allocate deflate state */
     
    8595    unsigned have;
    8696    z_stream strm;
    87     char in[CHUNK];
    88     char out[CHUNK];
     97    unsigned char in[CHUNK];
     98    unsigned char out[CHUNK];
    8999
    90100    /* allocate inflate state */
     
    168178    int ret;
    169179
     180    /* avoid end-of-line conversions */
     181    SET_BINARY_MODE(stdin);
     182    SET_BINARY_MODE(stdout);
     183
    170184    /* do compression if no arguments */
    171185    if (argc == 1) {
Note: See TracChangeset for help on using the changeset viewer.