1 | #ifndef __CRC32_H__ |
1 | #ifndef __CRC32_H__ |
2 | #define __CRC32_H__ |
2 | #define __CRC32_H__ |
3 | |
3 | |
4 | #ifndef _ANSI_ARGS_ |
4 | #include "ecb.h" |
5 | #ifdef PROTOTYPES |
5 | #include "uuint.h" |
6 | #define _ANSI_ARGS_(c) c |
|
|
7 | #else |
|
|
8 | #define _ANSI_ARGS_(c) () |
|
|
9 | #endif |
|
|
10 | #endif |
|
|
11 | |
6 | |
12 | #ifdef __cplusplus |
7 | #ifdef __cplusplus |
13 | extern "C" { |
8 | extern "C" { |
14 | #endif |
9 | #endif |
15 | |
10 | |
16 | typedef unsigned long crc32_t; |
11 | typedef uint32_t crc32_t; |
17 | #define Z_NULL 0 |
|
|
18 | |
12 | |
19 | crc32_t crc32 _ANSI_ARGS_((crc32_t crc, const unsigned char *buf, unsigned int len)); |
13 | #define CRC32_INIT ((crc32_t)0) |
|
|
14 | |
20 | /* |
15 | /* |
21 | Update a running crc with the bytes buf[0..len-1] and return the updated |
16 | * Update a running crc with the bytes buf[0..len-1] and return the updated |
22 | crc. If buf is NULL, this function returns the required initial value |
17 | * crc. If buf is NULL, this function returns the required initial value |
23 | for the crc. Pre- and post-conditioning (one's complement) is performed |
18 | * for the crc. Pre- and post-conditioning (one's complement) is performed |
24 | within this function so it shouldn't be done by the application. |
19 | * within this function so it shouldn't be done by the application. |
25 | Usage example: |
20 | * Usage example: |
|
|
21 | * |
|
|
22 | * uLong crc = CRC32_INIT; |
|
|
23 | * |
|
|
24 | * while (read_buffer (buffer, length) != EOF) { |
|
|
25 | * crc = crc32 (crc, buffer, length); |
|
|
26 | * } |
|
|
27 | * if (crc != original_crc) error (); |
|
|
28 | */ |
|
|
29 | UULIBINT_FUNC crc32_t uu_crc32 (crc32_t prev, const void *data, unsigned int len); |
26 | |
30 | |
27 | uLong crc = crc32(0L, Z_NULL, 0); |
31 | /* |
28 | |
32 | * This calculates the crc of a block of data consisting of two |
29 | while (read_buffer(buffer, length) != EOF) { |
33 | * parts, using only their CRCs. This is used to quickly combine |
30 | crc = crc32(crc, buffer, length); |
34 | * part CRCs into a full file CRC. |
31 | } |
|
|
32 | if (crc != original_crc) error(); |
|
|
33 | */ |
35 | */ |
|
|
36 | UULIBINT_FUNC uint32_t uu_crc32_combine (uint32_t crcA, uint32_t crcB, size_t lengthB); |
34 | |
37 | |
35 | #ifdef __cplusplus |
38 | #ifdef __cplusplus |
36 | } |
39 | } |
37 | #endif |
40 | #endif |
38 | #endif |
41 | #endif |