Compute crc checksum that linux cksum would produce for specified bytes. Based on IEEE Std 1003.1 - 2017.
More...
#include <Crc32.h>
|
| Crc32 () |
| Single default constructor.
|
unsigned | filecrc (const QString &filename) const |
| Compute the checksum using data in file.
|
unsigned | memcrc (const unsigned char *b, unsigned int n) const |
| Compute the checksum using data in memory.
|
Compute crc checksum that linux cksum would produce for specified bytes. Based on IEEE Std 1003.1 - 2017.
Definition at line 13 of file Crc32.h.
◆ Crc32()
Single default constructor.
Definition at line 65 of file Crc32.cpp.
◆ filecrc()
unsigned Crc32::filecrc |
( |
const QString & | filename | ) |
const |
Compute the checksum using data in file.
Definition at line 69 of file Crc32.cpp.
70{
72
73 unsigned i, c, b = 0;
74
75 QFile f (filename);
76 unsigned rtn = 0;
77 if (f.open (QFile::ReadOnly)) {
78 QByteArray array = f.readAll ();
79 int length = array.length ();
80
81 for (i = length; i > 0; --i) {
82 unsigned char chr = array [b++];
83 c = (unsigned) chr;
84 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
85 }
86
87
88 while (length != 0) {
89 c = length & 0377;
90 length >>= 8;
91 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
92 }
93
94 rtn = ~rtn;
95 }
96
97 return rtn;
98}
log4cpp::Category * mainCat
#define LOG4CPP_INFO_S(logger)
◆ memcrc()
unsigned Crc32::memcrc |
( |
const unsigned char * | b, |
|
|
unsigned int | n ) const |
Compute the checksum using data in memory.
Definition at line 100 of file Crc32.cpp.
101{
103
104 unsigned i, c, rtn = 0;
105
106 for (i = length; i > 0; --i) {
107 c = (unsigned)(*b++);
108 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
109 }
110
111
112 while (length != 0) {
113 c = length & 0377;
114 length >>= 8;
115 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
116 }
117
118 return ~rtn;
119}
The documentation for this class was generated from the following files: