summaryrefslogtreecommitdiff
path: root/plugins/FileAsMessage/crc32.cpp
diff options
context:
space:
mode:
authorAlexey Kulakov <panda75@bk.ru>2012-06-27 17:22:43 +0000
committerAlexey Kulakov <panda75@bk.ru>2012-06-27 17:22:43 +0000
commitf9eb107520e9dad37b06eb5c737b39d7bc15c751 (patch)
tree9a010a702ad582079966a6b3c2c162011d83b0d3 /plugins/FileAsMessage/crc32.cpp
parentd193e0b6402c482b9c42016452c3ed219f4f5e35 (diff)
Added File As Message plugin
git-svn-id: http://svn.miranda-ng.org/main/trunk@655 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/FileAsMessage/crc32.cpp')
-rw-r--r--plugins/FileAsMessage/crc32.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/FileAsMessage/crc32.cpp b/plugins/FileAsMessage/crc32.cpp
new file mode 100644
index 0000000000..e75eb6446e
--- /dev/null
+++ b/plugins/FileAsMessage/crc32.cpp
@@ -0,0 +1,29 @@
+const ulong CRCPoly = 0xEDB88320;
+ulong CRC32Table[256];
+
+void InitCRC32()
+{
+ for (UINT32 i = 0; i < 256; i++)
+ {
+ UINT32 r = i;
+ for (int j = 0; j < 8; j++)
+ if (r & 1)
+ r = (r >> 1) ^ CRCPoly;
+ else
+ r >>= 1;
+ CRC32Table[i] = r;
+ }
+}
+
+const ulong INITCRC = -1L;
+
+inline ulong UpdateCRC32(uchar val, ulong crc)
+{
+ return CRC32Table[(uchar)crc^val] ^ (crc>>8);
+}
+
+ulong memcrc32(uchar *ptr, int size, ulong crc )
+{
+ while(size--) crc = UpdateCRC32(*ptr++, crc);
+ return crc;
+}