File: crc32.c

package info (click to toggle)
retroarch 1.7.3%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 49,188 kB
  • sloc: ansic: 600,492; cpp: 23,670; objc: 8,299; asm: 6,404; sh: 2,203; xml: 2,144; makefile: 1,867; python: 1,582; java: 941; perl: 393
file content (43 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* gcc -O3 -o crc32 crc32.c -lz */

#include <stdio.h>
#include <errno.h>
#include <string.h>

#include <encodings/crc32.h>

int main(int argc, const char* argv[])
{
   if (argc != 2 )
   {
      fprintf( stderr, "Usage: crc32 <filename>\n" );
      return 1;
   }

   FILE *file = fopen(argv[1], "rb");

   if (file)
   {
      uint32_t crc = encoding_crc32(0L, NULL, 0 );

      for (;;)
      {
         uint8_t buffer[16384];

         int numread = fread((void*)buffer, 1, sizeof(buffer), file);

         if (numread > 0)
            crc = encoding_crc32( crc, buffer, numread );
         else
            break;
      }

      fclose(file);

      printf("%08x\n", crc);
      return 0;
   }

   fprintf(stderr, "Error opening input file: %s\n", strerror(errno));
   return 1;
}