File: crc.c

package info (click to toggle)
macutils 2.0b3-17
  • links: PTS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,256 kB
  • sloc: ansic: 12,737; makefile: 661
file content (44 lines) | stat: -rwxr-xr-x 757 bytes parent folder | download | duplicates (7)
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
44
/* crc.c; do crc calculation. */

#include <stdio.h>
#include "hexbin.h"
#include "crc.h"
#include "../util/masks.h"
#include "globals.h"

extern void exit();

unsigned long crc;

#ifdef HQX
void comp_q_crc(c)
register unsigned int c;
{
    unsigned char cc = c;

    crc = binhex_updcrc(crc, &cc, 1);
}

void comp_q_crc_n(s, e)
register unsigned char *s, *e;
{
    crc = binhex_updcrc(crc, s, e - s);
}
#endif /* HQX */

void verify_crc(calc_crc, file_crc)
unsigned long calc_crc, file_crc;
{
    calc_crc &= WORDMASK;
    file_crc &= WORDMASK;

    if(calc_crc != file_crc) {
        (void)fprintf(stderr, "CRC mismatch: got 0x%04lx, need 0x%04lx\n",
		file_crc, calc_crc);
#ifdef SCAN
	do_error("hexbin: CRC error");
#endif /* SCAN */
	exit(1);
    }
}