File CRC32 verification append and file CRC32 verification (0xedb88320)

Source: Internet
Author: User
Tags crc32

Unsigned char appengcrc32 (unsigned char * filename)
{
Unsigned long CRC = 0 xffffffff;
Unsigned int I;
Unsigned char res = 0;
Unsigned char buff [513];
Unsigned int realread;
File * FP;
Unsigned short filesize;

Fp = fopen (const char *) filename, "R + ");
Fread (& filesize, 1, 2, FP );
Filesize + = 4;
Fseek (FP, 0, seek_set );
Fwrite (& filesize, 2, 1, FP );

fseek (FP, 0, seek_set);
If (FP! = NULL)
{<
for (;)
{< br>
realread = fread (buff, 1,512, FP );
If (realread! = 0)
{< br> for (I = 0; I CRC = CRC32 [(CRC & 0xff) ^ buff [I])] ^ (CRC> 8);
}< br> else
break;
}< BR >}< br> CRC = ~ CRC;
fseek (FP, 0, seek_end);
fwrite (& CRC, 4,1, FP);
fclose (FP );
return 1;
}

Unsigned char wincheckcrc32 (unsigned char * filename)
{
Typedef struct
{
Signed int filesize;
Signed int accfp;
Unsigned long crcread;
} Tcrc32file;

Unsigned long CRC = 0 xffffffff;
Signed int I;
Unsigned char res = 0;
Unsigned char buff [513];
Signed int realread;

Tcrc32file crc32file;
File * FP;

Crc32file. accfp = 0;
Fp = fopen (filename, "rb ");
Fseek (FP, 0, seek_end );
Crc32file. filesize = ftell (FP );

Fseek (FP, seek_set, 0 );

If (FP! = NULL)
{< br> for (;)
{< br> realread = fread (buff, 1,512, FP );
If (realread> 0)
{< br> for (I = 0; I {< br> crc32file. accfp ++;
If (crc32file. accfp> crc32file. fileSize-4) break;
CRC = CRC32 [(CRC & 0xff) ^ buff [I])] ^ (CRC> 8 );
}< BR >}< br> else
break;
}< BR >}< br> CRC = ~ CRC;
fclose (FP);

Fp = fopen (filename, "rb ");
Fseek (FP,-4, seek_end );
Fread (& crc32file. crcread, 4,1, FP );
Fclose (FP );
Return (crc32file. crcread = CRC );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.