Last change
on this file since 2 was
2,
checked in by Sam Hocevar, 17 years ago
|
- imported original 0.7.0 tarball
|
File size:
716 bytes
|
Rev | Line | |
---|
[2] | 1 | #include "crc.hpp" |
---|
| 2 | |
---|
| 3 | unsigned short calc_crc(unsigned char *buf, long len) |
---|
| 4 | { |
---|
| 5 | unsigned char c1=0,c2=0; |
---|
| 6 | while (len) |
---|
| 7 | { |
---|
| 8 | len--; |
---|
| 9 | c1+=*buf; |
---|
| 10 | c2+=c1; |
---|
| 11 | buf++; |
---|
| 12 | } |
---|
| 13 | return (c2<<8)|c1; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | ulong crc_file(bFILE *fp) |
---|
| 19 | { |
---|
| 20 | uchar crc1=0,crc2=0,crc3=0,crc4=0; |
---|
| 21 | |
---|
| 22 | int size=0x1000; |
---|
| 23 | uchar *buffer=(uchar *)jmalloc(size,"crc_buffer"),*c; |
---|
| 24 | long l=fp->file_size(); |
---|
| 25 | long cur_pos=fp->tell(); |
---|
| 26 | fp->seek(0,0); |
---|
| 27 | while (l) |
---|
| 28 | { |
---|
| 29 | int nr=fp->read(buffer,size); |
---|
| 30 | if (nr==0) l=0; |
---|
| 31 | else |
---|
| 32 | { |
---|
| 33 | l-=nr; |
---|
| 34 | for (c=buffer;nr;nr--,c++) |
---|
| 35 | { |
---|
| 36 | crc1+=*c; |
---|
| 37 | crc2+=crc1; |
---|
| 38 | crc3+=crc2; |
---|
| 39 | crc4+=crc3; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | fp->seek(cur_pos,0); |
---|
| 44 | jfree(buffer); |
---|
| 45 | return (crc1|(crc2<<8)|(crc3<<16)|(crc4<<24)); |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.