chksum.c 2.4 KB

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