]> git.kernelconcepts.de Git - metawatch.git/blobdiff - crc16ccitt.c
Add DBus based freedesktop.org Notify support (uh, still a little hacky),
[metawatch.git] / crc16ccitt.c
index d468c80f5ea40425c23ec82e59c1268ba5876730..ae0efe375645491829f2f3314169ace239bb5c33 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * derived from crctester.c
+ * derived from crctester.c 2011 by Nils Faerber <nils.faerber@kernelconcepts.de>
  * original header:
  * ----------------------------------------------------------------------------
  * CRC tester v1.3 written on 4th of February 2003 by Sven Reifegerste (zorc/reflex)
  * original header:
  * ----------------------------------------------------------------------------
  * CRC tester v1.3 written on 4th of February 2003 by Sven Reifegerste (zorc/reflex)
@@ -100,12 +100,19 @@ static unsigned long crctablefast (unsigned char* p, unsigned long len)
 
        unsigned long crc = crcinit_direct;
 
 
        unsigned long crc = crcinit_direct;
 
-       if (refin) crc = reflect(crc, order);
+       if (refin)
+               crc = reflect(crc, order);
+
+       if (!refin)
+               while (len--)
+                       crc = (crc << 8) ^ crctab[ ((crc >> (order-8)) & 0xff) ^ *p++];
+       else
+               while (len--)
+                       crc = (crc >> 8) ^ crctab[ (crc & 0xff) ^ *p++];
 
 
-       if (!refin) while (len--) crc = (crc << 8) ^ crctab[ ((crc >> (order-8)) & 0xff) ^ *p++];
-       else while (len--) crc = (crc >> 8) ^ crctab[ (crc & 0xff) ^ *p++];
+       if (refout^refin)
+               crc = reflect(crc, order);
 
 
-       if (refout^refin) crc = reflect(crc, order);
        crc^= crcxor;
        crc&= crcmask;
 
        crc^= crcxor;
        crc&= crcmask;
 
@@ -114,8 +121,8 @@ static unsigned long crctablefast (unsigned char* p, unsigned long len)
 
 static unsigned long crctable (unsigned char* p, unsigned long len)
 {
 
 static unsigned long crctable (unsigned char* p, unsigned long len)
 {
-       // normal lookup table algorithm with augmented zero bytes.
-       // only usable with polynom orders of 8, 16, 24 or 32.
+       /* normal lookup table algorithm with augmented zero bytes. */
+       /* only usable with polynom orders of 8, 16, 24 or 32. */
 
        unsigned long crc = crcinit_nondirect;
 
 
        unsigned long crc = crcinit_nondirect;
 
@@ -138,6 +145,7 @@ static unsigned long crctable (unsigned char* p, unsigned long len)
 
        if (refout^refin)
                crc = reflect(crc, order);
 
        if (refout^refin)
                crc = reflect(crc, order);
+
        crc^= crcxor;
        crc&= crcmask;
 
        crc^= crcxor;
        crc&= crcmask;
 
@@ -148,8 +156,8 @@ static unsigned long crctable (unsigned char* p, unsigned long len)
 
 unsigned long crcbitbybit(unsigned char* p, unsigned long len) {
 
 
 unsigned long crcbitbybit(unsigned char* p, unsigned long len) {
 
-       // bit by bit algorithm with augmented zero bytes.
-       // does not use lookup table, suited for polynom orders between 1...32.
+       /* bit by bit algorithm with augmented zero bytes. */
+       /* does not use lookup table, suited for polynom orders between 1...32. */
 
        unsigned long i, j, c, bit;
        unsigned long crc = crcinit_nondirect;
 
        unsigned long i, j, c, bit;
        unsigned long crc = crcinit_nondirect;
@@ -179,6 +187,7 @@ unsigned long crcbitbybit(unsigned char* p, unsigned long len) {
 
        if (refout)
                crc=reflect(crc, order);
 
        if (refout)
                crc=reflect(crc, order);
+
        crc ^= crcxor;
        crc &= crcmask;
 
        crc ^= crcxor;
        crc &= crcmask;
 
@@ -365,3 +374,4 @@ int main() {
        return(0);
 }
 #endif
        return(0);
 }
 #endif
+