zlib Checksum Functions

Syntax

#include <cafe.h>  
#include <zlib.h>

ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));

ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));

Parameters

adler For adler32. The running checksum.
crc For crc32. The running checksum.
buf Data to checksum.
len Length of data in buf

Return Value

The current checksum.

Description

These functions are not related to compression but are exported anyway because they might be useful in applications using the compression library.

adler32

Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. If buf is NULL, this function returns the required initial value for the checksum.

An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much faster.

Usage Example

     uLong adler = adler32(0L, Z_NULL, 0);
 
     while (read_buffer(buffer, length) != EOF) {
       adler = adler32(adler, buffer, length);
     }
     if (adler != original_adler) error();

crc32

Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. If buf is Z_NULL, this function returns the required initial value for the for the crc. Pre and post-conditioning (one's complement) is performed within this function so it should not be performed by the application.

Usage Example

     uLong crc = crc32(0L, Z_NULL, 0);
 
     while (read_buffer(buffer, length) != EOF) {
       crc = crc32(crc, buffer, length);
     }
     if (crc != original_crc) error();

Do Not Call From

adler32

None.

crc32

None.

See Also

zlib Overview

Revision History

2014/12/05 Creation.


CONFIDENTIAL