Last change
on this file since 18 was
17,
checked in by Sam Hocevar, 17 years ago
|
- absolute shitloads of 64 bit fixes.
|
File size:
706 bytes
|
Rev | Line | |
---|
[2] | 1 | #include "crc.hpp" |
---|
| 2 | |
---|
[17] | 3 | uint16_t calc_crc(uint8_t *buf, int len) |
---|
[2] | 4 | { |
---|
[17] | 5 | uint8_t c1=0,c2=0; |
---|
[2] | 6 | while (len) |
---|
| 7 | { |
---|
| 8 | len--; |
---|
| 9 | c1+=*buf; |
---|
| 10 | c2+=c1; |
---|
| 11 | buf++; |
---|
| 12 | } |
---|
| 13 | return (c2<<8)|c1; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
[17] | 18 | uint32_t crc_file(bFILE *fp) |
---|
[2] | 19 | { |
---|
[17] | 20 | uint8_t crc1=0,crc2=0,crc3=0,crc4=0; |
---|
[2] | 21 | |
---|
| 22 | int size=0x1000; |
---|
[17] | 23 | uint8_t *buffer=(uint8_t *)jmalloc(size,"crc_buffer"),*c; |
---|
[2] | 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.