3 * Checks CRC values for resource files
5 * v. 1.00 (24 August 1993)
7 * © 1993-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 * long crc__doCRC(char *filename,int offset)
43 * Returns the CRC value for a file starting from a certain offset.
46 * char *filename == the resource filename to use
47 * int offset == the offset to start from
53 static long crc__doCRC(char *filename,int offset)
59 fp=res_openfile(filename,"rb");
62 werr(FALSE,msgs_lookup("crcFNF:Couldn't open file '%s'."),filename);
65 fseek(fp,offset,SEEK_SET);
68 read=fread(buffer,1,1024,fp);
69 c=crc32(c,buffer,read,1);
77 * long crc(char *filename)
80 * Calculates the CRC value for the file specified. Uses the same method
84 * char *filename == the filename of the file to check (leaf only - it's
85 * passed through res_findname()). Note that CRC-checking the
86 * '!RunImage' file is rather silly.
92 long crc(char *filename)
94 return (crc__doCRC(filename,0));
98 * void crc_check(char *filename,int check)
101 * Checks a CRC value for a file and reports a fatal error if the check
105 * char *filename == the leafname of the file
106 * long check == the CRC number to check with
109 void crc_check(char *filename,long check)
113 if (crc__doCRC(filename,0)!=check)
118 msgs_lookup("crcFC:%s resource file '%s' has been corrupted. "
119 "Please restore this file from the distribution disk."),
128 * void crc_checkRunImage(void)
131 * Corruption-checks the main !RunImage file. It must have been passed
132 * through CodeScr first, to install the CRC into the code.
135 void crc_checkRunImage(void)
137 FILE *fp=res_openfile("!RunImage","r");
140 werr(TRUE,msgs_lookup("crcFNF:Couldn't open file '%s'."),"!RunImage");
141 fseek(fp,8,SEEK_SET);
144 if (c!=crc__doCRC("!RunImage",12))
149 msgs_lookup("crcFC:%s resource file '%s' has been corrupted. "
150 "Please restore this file from the distribution disk."),