1 /* chksum.c -- compute a checksum
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 #include "lzo/lzoconf.h"
32 #define WANT_LZO_MALLOC 1
33 #include "examples/portab.h"
36 /*************************************************************************
38 **************************************************************************/
40 int main(int argc
, char *argv
[])
44 lzo_uint32_t adler
, crc
;
46 if (argc
< 0 && argv
== NULL
) /* avoid warning about unused args */
49 if (lzo_init() != LZO_E_OK
)
51 printf("lzo_init() failed !!!\n");
55 /* prepare the block */
56 block_size
= 128 * 1024L;
57 block
= (lzo_bytep
) lzo_malloc(block_size
);
60 printf("out of memory\n");
63 lzo_memset(block
, 0, block_size
);
65 /* adler32 checksum */
66 adler
= lzo_adler32(0, NULL
, 0);
67 adler
= lzo_adler32(adler
, block
, block_size
);
68 if (adler
!= 0x001e0001UL
)
70 printf("adler32 checksum error !!! (0x%08lx)\n", (long) adler
);
75 crc
= lzo_crc32(0, NULL
, 0);
76 crc
= lzo_crc32(crc
, block
, block_size
);
77 if (crc
!= 0x7ee8cdcdUL
)
79 printf("crc32 checksum error !!! (0x%08lx)\n", (long) crc
);
84 printf("Checksum test passed.\n");
89 /* vim:set ts=4 sw=4 et: */