Sunday, December 24, 2006

Checksum, Please

I was playing around with file comparisons recently, and I thought I could have some fun with crc32(). It's a common function, so it's probably in the system somewhere already. I asked man about it and there it is, in the 'n' section of the man pages:

DESCRIPTION
This package provides a Tcl-only implementation of the CRC-32 algorithm based upon information provided at http://www.naaccr.org/standard/crc32/document.html If the Trf package is available then the crc-zlib command is used to perform the calculation.

Tcl-only, great. And searching the XCode docs just lead to the same man page. But I couldn't believe there's not a C function in the system somewhere, so I asked google to have a look at the Darwin source, and found this page. Ah, it's part of zlib, as mentioned in the man page description. No wonder Apple has no docs describing it.

So next time you need a 32-bit checksum, add -lz to your linker flags and send me a postcard.

No comments: