title: POSIX cksum and Boost.CRC
body: <p>I'm trying to implement the simple POSIX <code>cksum</code> using Boost.CRC.</p>
  
  <p>The code I'm using amounts to this:</p>
  
  <pre><code>for(int i = 1; i&lt;argc; ++i)
  {
    support::file current(argv[i], support::file::access::read);
    size_t octets = 0;
    boost::crc_32_type crc;
    while(true)
    {
      size_t bytes_read = current.read_some(buffer_size, buffer);
      octets += bytes_read;
      crc.process_bytes(&amp;buffer[0], bytes_read);
      if(bytes_read &lt; buffer_size)
        break;
    }
    if(i&gt;1)
      support::print("\n");
  
    support::print(boost::lexical_cast&lt;string&gt;(crc.checksum()) + " " + boost::lexical_cast&lt;string&gt;(octets) + " " + argv[i]);
  }
  </code></pre>
  
  <p>Where <code>support::file</code> is a simple <code>fopen</code>/<code>fread</code> binary file I/O wrapper, which I succesfully used for a <code>cat</code> implementation. <code>support::print</code> gives the same output as <code>std::cout</code>, but I need it for reliable non-ASCII output on Windows.</p>
  
  <p>The Boost header has this:</p>
  
  <pre><code>typedef crc_optimal&lt;32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true&gt; crc_32_type;
  </code></pre>
  
  <p>as the only 32-bit CRC typedef. It gives the wrong answer (checked with GNUWin32 coreutils <code>cksum</code>) for an empty file (<code>touch test &amp;&amp; cksum test</code>). I have tried using the above typedef and modifying one or both of the <code>0xFFFFFFFF</code> values to 0, I get the correct result for an empty file, but any other file still gives different results.</p>
  
  <p>How is Boost.CRC related to the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cksum.html#tag_20_19" rel="nofollow">POSIX <code>cksum</code> specification</a>?</p>