Skip to content
Snippets Groups Projects
Commit f4ae099c authored by rswindell's avatar rswindell
Browse files

New function (fcrc32) to calculate CRC32 of byte range from file stream.

parent 0c80d4c1
No related branches found
No related tags found
No related merge requests found
......@@ -89,5 +89,18 @@ unsigned long crc32(char *buf, unsigned long len)
return(~crc);
}
unsigned long fcrc32(FILE* fp, unsigned long len)
{
int ch;
unsigned long l,crc=0xffffffff;
rewind(fp);
for(l=0;(len==0 || l<len) && !feof(fp);l++) {
if((ch=fgetc(fp))==EOF)
break;
crc=ucrc32(ch,crc);
}
return(~crc);
}
......@@ -38,6 +38,8 @@
#ifndef _CRC32_H_
#define _CRC32_H_
#include <stdio.h> /* FILE */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -45,6 +47,7 @@ extern "C" {
extern long crc32tbl[];
unsigned long crc32(char* buf, unsigned long len);
unsigned long fcrc32(FILE* fp, unsigned long len);
#ifdef __cplusplus
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment