VirtualBox

source: vbox/trunk/src/libs/liblzma-5.4.1/check/crc32_small.c@ 100111

Last change on this file since 100111 was 98730, checked in by vboxsync, 22 months ago

libs/liblzma-5.4.1: Export to OSE, bugref:10254

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2//
3/// \file crc32_small.c
4/// \brief CRC32 calculation (size-optimized)
5//
6// Author: Lasse Collin
7//
8// This file has been put into the public domain.
9// You can do whatever you want with this file.
10//
11///////////////////////////////////////////////////////////////////////////////
12
13#include "check.h"
14
15
16uint32_t lzma_crc32_table[1][256];
17
18
19#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
20__attribute__((__constructor__))
21#endif
22static void
23crc32_init(void)
24{
25 static const uint32_t poly32 = UINT32_C(0xEDB88320);
26
27 for (size_t b = 0; b < 256; ++b) {
28 uint32_t r = b;
29 for (size_t i = 0; i < 8; ++i) {
30 if (r & 1)
31 r = (r >> 1) ^ poly32;
32 else
33 r >>= 1;
34 }
35
36 lzma_crc32_table[0][b] = r;
37 }
38
39 return;
40}
41
42
43#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
44extern void
45lzma_crc32_init(void)
46{
47 mythread_once(crc32_init);
48 return;
49}
50#endif
51
52
53extern LZMA_API(uint32_t)
54lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
55{
56#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
57 lzma_crc32_init();
58#endif
59
60 crc = ~crc;
61
62 while (size != 0) {
63 crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
64 --size;
65 }
66
67 return ~crc;
68}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette