summaryrefslogtreecommitdiffhomepage
path: root/src/crc/mdso_crc32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crc/mdso_crc32.c')
-rw-r--r--src/crc/mdso_crc32.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/crc/mdso_crc32.c b/src/crc/mdso_crc32.c
new file mode 100644
index 0000000..1e3f6f6
--- /dev/null
+++ b/src/crc/mdso_crc32.c
@@ -0,0 +1,32 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <unistd.h>
+
+#include <mdso/mdso.h>
+#include <mdso/mdso_crc32.h>
+
+static const uint32_t crc32_table[256] = MDSO_CRC32_TABLE;
+
+uint32_t mdso_crc32_mbstr(const unsigned char * str, size_t * symlen)
+{
+ const unsigned char * ch;
+ uint32_t crc32;
+
+ crc32 = 0 ^ 0xFFFFFFFF;
+ ch = str;
+
+ while (*ch) {
+ crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF];
+ ch++;
+ }
+
+ if (symlen)
+ *symlen = ch - str;
+
+ return (crc32 ^ 0xFFFFFFFF);
+}