diff --git a/Makefile b/Makefile index 11786ac..3136130 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ all: thin_repair thin_dump thin_restore SOURCE=\ + checksum.cc \ endian_utils.cc \ error_set.cc \ metadata.cc \ @@ -14,7 +15,7 @@ OBJECTS=$(subst .cc,.o,$(SOURCE)) TOP_DIR:=$(PWD) CPPFLAGS=-Wall -g -I$(TOP_DIR) #CPPFLAGS=-Wall -std=c++0x -g -I$(TOP_DIR) -LIBS=-lstdc++ +LIBS=-lz -lstdc++ .PHONEY: test-programs diff --git a/checksum.cc b/checksum.cc new file mode 100644 index 0000000..4dd37ab --- /dev/null +++ b/checksum.cc @@ -0,0 +1,25 @@ +#include "checksum.h" + +#include + +using namespace base; + +//---------------------------------------------------------------- + +crc32::crc32(uint32_t seed) + : sum_(seed) { +} + +void +crc32::append(void const *buffer, unsigned len) +{ + sum_ = ::crc32(sum_, reinterpret_cast(buffer), len); +} + +uint32_t +crc32::get_sum() const +{ + return sum_; +} + +//---------------------------------------------------------------- diff --git a/checksum.h b/checksum.h new file mode 100644 index 0000000..76f4f9d --- /dev/null +++ b/checksum.h @@ -0,0 +1,22 @@ +#ifndef CHECKSUM_H +#define CHECKSUM_H + +#include + +//---------------------------------------------------------------- + +namespace base { + class crc32 { + crc32(uint32_t seed); + + void append(void const *buffer, unsigned len); + uint32_t get_sum() const; + + private: + uint32_t sum_; + }; +} + +//---------------------------------------------------------------- + +#endif